Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestMapping works on private methods [SPR-16878] #21417

Closed
spring-projects-issues opened this issue May 28, 2018 · 4 comments
Closed

RequestMapping works on private methods [SPR-16878] #21417

spring-projects-issues opened this issue May 28, 2018 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

Vipin VijayKumar opened SPR-16878 and commented

Where would we use @RequestMapping with private methods? Is there a specific use case

The reason why I am asking this is that I noticed that @RequestMapping worked on private methods as well. Why is this so?

Is it because spring access these methods through reflections so access modifiers aren't really considered? Is this a bug or a feature that has uses?

 


No further details from SPR-16878

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This indeed works as designed. We generally don't restrict visibility declarations on reflective methods, leaving that choice up to the developer. That said, for this particular case, I would recommend public declarations or potentially package-visible declarations (without a visibility keyword), with private handler methods actually being more of a niche effect here.

@spring-projects-issues
Copy link
Collaborator Author

Vipin VijayKumar commented

Ok, so it's not recommended make these methods private right? Also, about niche cases? Any example if you could suggest?

@spring-projects-issues
Copy link
Collaborator Author

Vipin VijayKumar commented

Also thank you for the quick response :) 

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, private isn't recommended there. I'm sure some people do it for some reasons but I'm not aware of any worthwhile niches myself. At the same time, we can't easily take it back since it has been possible for many years... and it is fundamentally in line with our general handling of non-public methods.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants