再次在任何 @PostConstruct 之前注入所有 @Resource
JSR-250 表示所有 @Resource 注释方法都将在 @PostConstruct 方法之前调用。
我的问题是:
这是否意味着上下文中所有 bean 上的所有 @Resource 注释方法都将在调用任何 @PostConstruct 注释方法之前调用? 或者换句话说,一旦注入了依赖关系,即使上下文中的其他 bean 仍未注入依赖关系,是否可以调用 beans @PostConstruct 方法?
问候, 蒂姆.
JSR-250 says all @Resource annotated methods will be called before the @PostConstruct method..
My question is:
Does that mean that all @Resource annotated methods on all beans in a context will be called before any @PostConstruct annotated methods are called?
Or in other words can a beans @PostConstruct method be called once its dependencies have been injected even if other beans in the context still haven't had there dependences injected?
Regards,
Tim.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保证当给定 bean 的
@PostConstruct
被调用时,它的所有@Resource
字段都将被注入。如果这些注入中的任何一个本身都是具有自己的@Resource
和@PostConstruct
的 bean,那么它们将已经被调用。换句话说,在调用任何给定的 @PostConstruct 时,可以保证其所有依赖项都已完全初始化。事实上,在
BeanB
实例化之前,BeanA
可能会通过@PostConstruct
被构造和初始化, ifBeanB
对BeanA
没有明确的依赖关系。It is guaranteed that when a given bean's
@PostConstruct
gets called, that all of its@Resource
fields will have been injected. If any of those injections are themselves beans with their own@Resource
and@PostConstruct
, then those will have already been called. In other words, by the time any given@PostConstruct
is called, it is guaranteed that all of its dependencies have been fully initialized.It is possible, and in fact likely, that
BeanA
will be constructed and initialized via@PostConstruct
beforeBeanB
has even been instantiated, ifBeanB
has no expressed dependency onBeanA
.