My project at current job use private access modifier for methods of MVC controllers:
@Controller
public class HelloWorldController {
@RequestMapping("/helloWorld")
private ModelAndView helloWorld() {
I have integrated PMD and his report has a lot of:
/src/main/java/com/web/controller/SignalController.java:91: Avoid unused private
methods such as 'handleNewRequest()'.
So instead of disabling useful PMD rule I think to change controller's methods visibility to public.
Are there any reasons to keep controller's methods private?
So if you are using latest spring version you can directly replace @Controller with @RestController without any issue.
Unfortunately, this is not possible. The request mapping has to be unique otherwise the application can't determine which method the incoming request should be mapped to.
The @Controller annotation indicates that a particular class serves the role of a controller. There is no need to extend any controller base class or reference the Servlet API. You are of course still able to reference Servlet-specific features if you need to.
What is Controller ? Controller is, thread-safe class, capable of handling multiple HTTP requests throughout the lifecycle of an application. CrudRepository provides sophisticated CRUD functionality for the entity class that is being managed.
You're shooting yourself in the foot by making it private:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With