[英]'@Inject thread bean in @Service' or '@Inject service bean in @Component', which is more reasonable architecture?
I am using SpringFramework for web server. 我正在将SpringFramework用于Web服务器。
Sometimes I need to do asynchronous task to implement certain function. 有时我需要执行异步任务来实现某些功能。
Usually, I prefer to use 通常,我更喜欢使用
But I am not sure is it OK or not. 但我不确定是否可以。
So I got a question just like the title. 所以我有一个和标题一样的问题。
@Inject thread bean in @Service
' @Inject thread bean in @Service
的@Inject thread bean in @Service
' OR 要么
@Inject service bean in @Component
' @Inject service bean in @Component
的@Inject service bean in @Component
' I want to know which way is more frequently uses. 我想知道哪种方式更常用。
Thanks in advance:D 提前致谢
Have a good Day! 祝你有美好的一天!
EDIT: 编辑:
Based on edited question and commentary the answer has been changed. 根据已编辑的问题和评论,答案已更改。
@Component is generic @Service is specific @Component是通用的@Service是特定的
@Inject is replaced by @Autowired @Inject替换为@Autowired
You always want to use @Autowired @Service instead of other combinations. 您始终希望使用@Autowired @Service而不是其他组合。
For architectural differences you will only get information from the API documents themselves. 对于架构差异,您只能从API文档本身获取信息。
for further detail check this out: 有关更多详细信息,请查看以下内容:
What's the difference between @Component, @Repository & @Service annotations in Spring? Spring中的@ Component,@ Repository和@Service批注有什么区别?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.