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

后端 未结 29 2603
时光说笑
时光说笑 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条回答
  •  孤城傲影
    2020-11-22 00:48

    @Repository @Service and @Controller are serves as specialization of @Component for more specific use on that basis you can replace @Service to @Component but in this case you loose the specialization.

    1. **@Repository**   - Automatic exception translation in your persistence layer.
    2. **@Service**      - It indicates that the annotated class is providing a business service to other layers within the application.
    

提交回复
热议问题