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?
Asked
Active
Viewed 314 times
3

Harshal Patil
- 6,659
- 8
- 41
- 57

Harshana
- 7,297
- 25
- 99
- 173
1 Answers
0
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.

Gabriel Ruiu
- 2,753
- 2
- 19
- 23