@controller: By using that annotation we do two things, first we declare that this class is a Spring bean and should be created and maintained by Spring ApplicationContext, but also we indicate that its a controller in MVC setup.
For example, DispatcherServlet will look for @RequestMapping on classes which are annotated using @Controller but not with @Component.
They are scanned because they themselves are annotated with @Component annotation. If you define your own custom annotation and annotate it with @Component, then it will also get scanned with <context:component-scan>.
@Component is a generic stereotype for any Spring-managed component or bean.
@Repository is a stereotype for persistence layer.
@Service is a stereotype for the service layer.
@Controller is a stereotype for presentation layer (spring-MVC).
Ref: https://javarevisited.blogspot.com/2017/11/difference-between-component-service.html#more
For example, DispatcherServlet will look for @RequestMapping on classes which are annotated using @Controller but not with @Component.
They are scanned because they themselves are annotated with @Component annotation. If you define your own custom annotation and annotate it with @Component, then it will also get scanned with <context:component-scan>.
@Component is a generic stereotype for any Spring-managed component or bean.
@Repository is a stereotype for persistence layer.
@Service is a stereotype for the service layer.
@Controller is a stereotype for presentation layer (spring-MVC).
Ref: https://javarevisited.blogspot.com/2017/11/difference-between-component-service.html#more
No comments:
Post a Comment