“@ Services中的@Inject线程bean”或“@Component中的@Inject服务bean”,这是更合理的架构吗?

时间:2014-07-01 01:37:31

标签: multithreading spring architecture dependency-injection javabeans

我正在将SpringFramework用于Web服务器。

有时我需要执行异步任务来实现某些功能。

通常,我更喜欢使用

  • @Inject @Component(实现Runnable)在@Service。

但我不确定是否可以。

所以我得到了一个像标题一样的问题。

  • ' @Inject thread bean in @Service'

OR

  • ' @Inject service bean in @Component'

我想知道哪种方式更常用。

提前致谢:D

祝你有个美好的一天!

1 个答案:

答案 0 :(得分:0)

编辑:

根据编辑过的问题和评论,答案已经改变。

@Component是通用的 @Service是具体的

@Inject被@Autowired

取代

您总是希望使用@Autowired @Service而不是其他组合。

对于架构差异,您只能从API文档中获取信息。

有关详细信息,请查看以下内容:

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

相关问题