创建所有bean之后,Spring setter依赖项注入 [英] Spring setter dependency injection after all beans have been created

查看:167
本文介绍了创建所有bean之后,Spring setter依赖项注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组使用构造函数注入创建的Spring Bean.由于存在(按设计)对其他bean的循环引用,因此我希望在所有这些bean创建完成后对其进行后处理,以注入对其他bean的引用.

I have a set of Spring beans created using constructor injection. Since there are (by design) circular references to other beans, I'd like to post-process the beans once they are all created to inject the references to other beans.

最初使用BeanPostProcessor的尝试表明BeanPostProcessor在实例化每个bean之后运行,而不是等到所有实例都被实例化.

Initial attempts at using BeanPostProcessor show that the BeanPostProcessor is running after EACH bean is instantiated, not waiting until all have been instantiated.

Spring是否提供了一种机制,可以在创建完所有bean之后对它们进行后处理?

Does Spring provide a mechanism for post-processing as set of beans after all have been created?

推荐答案

如果要在ApplicationContext中创建bean,则ApplicationContext会将ApplicationEvent触发到任何已注册的ApplicationListener回调.其中之一应该告诉您何时通过Spring将上下文中的所有bean连接在一起.

If you're creating the beans in an ApplicationContext, the ApplicationContext fires ApplicationEvents to any registered ApplicationListener callbacks. One of those should tell you when all the beans in the context are wired together via Spring.

这篇关于创建所有bean之后,Spring setter依赖项注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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