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

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

    @Component is the top level generic annotation which makes the annotated bean to be scanned and available in the DI container

    @Repository is specialized annotation and it brings the feature of converting all the unchecked exceptions from the DAO classes

    @Service is specialized annotation. it do not bring any new feature as of now but it clarifies the intent of the bean

    @Controller is specialized annotation which makes the bean MVC aware and allows the use of further annotation like @RequestMapping and all such

    Here are more details

提交回复
热议问题