我已经在What's the difference between @Component, @Repository & @Service annotations in Spring?
中了解了每个Spring注释我知道@Component
和@Service
在Spring Framework中几乎完全相同。它的区别在于它的用途,因此我只需将@Service
用于服务层,即可访问我的存储库。< / p>
我想知道选择@Component
而不是@Service
的更好方法是什么。请注意,我现在正在为我创建的工厂使用@Component
,因为工厂不需要处理存储库。
答案 0 :(得分:5)
请记住,这些是Spring的刻板印象,应该适用于通常应用围绕一个代码的刻板印象或假设。
@Component
。@Service
。 Spring将这两者最终视为@Component
。