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

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

    Repository and Service are children of Component annotation. So, all of them are Component. Repository and Service just expand it. How exactly? Service has only ideological difference: we use it for services. Repository has particular exception handler.

提交回复
热议问题