开发者

All @Resource injection before any @PostConstruct again

JSR-250 says all @Resource annotated methods will be called before the @PostConstruct method..

My question is:

Does that mean that all @Resource开发者_如何学Go 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.


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 before BeanB has even been instantiated, if BeanB has no expressed dependency on BeanA.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜