自动连接到列表中时的Bean顺序 [英] Bean order when autowired into list

查看:77
本文介绍了自动连接到列表中时的Bean顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经定义了接口IWorker及其一些实现,分别为WorkerAWorkerB,均用@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注释的其他WorkerCWorkerD(也是IWorker的实现)自动连接到同一列表中?

      How can I let additional WorkerC and WorkerD (also implementations of IWorker) not annotated with @Component be autowired into the same list via my applicationContext.xml?

      是否保留了xml中WorkerCWorkerD的顺序?

      Is the order of WorkerC and WorkerD 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆