自动连接到列表中时的Bean顺序 [英] Bean order when autowired into list
问题描述
我已经定义了接口IWorker
及其一些实现,分别为WorkerA
和WorkerB
,均用@Component
注释.
I have defined an interface IWorker
and some implementations of it as WorkerA
and WorkerB
, both annotated with @Component
.
然后我通过以下方式将它们自动连接到我的应用程序中:
I then autowire them into my app via:
@Autowired
private List<IWorker> workers = new ArrayList<IWorker>();
-
根据什么顺序将工人放入列表中?
From what does the order the workers are put into the list depend on?
如何通过我的
applicationContext.xml
将未使用@Component
注释的其他WorkerC
和WorkerD
(也是IWorker
的实现)自动连接到同一列表中?How can I let additional
WorkerC
andWorkerD
(also implementations ofIWorker
) not annotated with@Component
be autowired into the same list via myapplicationContext.xml
?是否保留了xml中
WorkerC
和WorkerD
的顺序?Is the order of
WorkerC
andWorkerD
from the xml preserved?我是否可以依靠规则将工作人员A,B,C和D放入列表的顺序?
Is there a rule I can rely on in which order worker A, B, C and D will be put into the list?
推荐答案
如果要在Spring注入的List中对这些依赖项进行排序,请使用@Order批注.
If you want to order these dependencies in the List injected by Spring, then use @Order annotation.
这篇关于自动连接到列表中时的Bean顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!