Thursday, 2 August 2018

@Component, @Service, @Controller, and @Repository in Spring

@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

No comments:

Post a Comment

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...