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

后端 未结 29 2163
时光说笑
时光说笑 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:41

    Annotate other components with @Component, for example REST Resource classes.

    @Component
    public class AdressComp{
        .......
        ...//some code here    
    }
    

    @Component is a generic stereotype for any Spring managed component.

    @Controller, @Service and @Repository are Specializations of @Component for specific use cases.

    @Component in Spring

提交回复
热议问题