当我有多个实现ApplicationListener<ContextRefreshedEvent>
的bean时接口(interface),如何控制某些 bean 在其他 bean 之前被调用?
在 bean 本身内部处理依赖关系是否更有意义?
最佳答案
在AbstractApplicationContext
中,我可以看到以下代码片段,它负责注册ApplicationListener
实现的bean。
Collection listeners = getBeansOfType(ApplicationListener.class, true, false).values();
for (Iterator it = listeners.iterator(); it.hasNext();) {
addListener((ApplicationListener) it.next());
}
这里 getBeansOfType
发现返回 Map
,因此排序是非确定性。这是 spring-2.0
的工作方式。
关于java - 如何控制 ApplicationListener bean 的调用顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14835079/