What's the difference between @Component, @Repository & @Service annotations in Spring?

后端 未结 29 2640
时光说笑
时光说笑 2020-11-22 00:33

Can @Component, @Repository and @Service annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device?

29条回答
  •  萌比男神i
    2020-11-22 00:45

    In spring framework provides some special type of annotations,called stereotype annotations. These are following:-

    @RestController- Declare at controller level.
    @Controller – Declare at controller level.
    @Component – Declare at Bean/entity level.
    @Repository – Declare at DAO level.
    @Service – Declare at BO level.
    

    above declared annotations are special because when we add into xxx-servlet.xml file ,spring will automatically create the object of those classes which are annotated with above annotation during context creation/loading phase.

提交回复
热议问题