【发布时间】:2018-01-18 18:53:42
【问题描述】:
我已经阅读了What's the difference between @Component, @Repository & @Service annotations in Spring? 中的每个 Spring 注释
我知道 @Component 和 @Service 在 Spring Framework 中的作用几乎相同。区别在于它的用途,所以我只是在 服务层 中使用@Service 来访问我的存储库。
我想知道选择@Component 而不是@Service 的更好方法是什么。请注意,我现在将@Component 用于我创建的工厂,因为工厂不需要处理存储库。
【问题讨论】:
-
最终没关系,只使用你认为合乎逻辑的东西。有时我在不使用存储库的类上使用@Service,而只使用其他服务。
标签: java spring spring-boot software-quality