As Spring has the annotation @Component to represent any Spring manage component. Then again we use @Controller to in a MVC controller bean. But What extra advantage i get use @Controller over @Component? If we use @Controller instead of @Component is it for more clarity on layers or is there any additional support give by Spring?
Add a comment
|
1 Answer
The @Controller is used specifically used in SpringMVC and indicates that the annotated class has the role of a controller, and this in turn allows the Spring DispatcherServlet to identify potential handlers for requests to the particular service.
When the DispatcherServlet receives a request, it delegates it to the appropriate controller, based on its @RequestMapping and @Controller values.
@Component indicates that the class itself should be managed by the Spring container.
Both are similiar in the fact they are discovered by the classpath scanning.