All @Resource injections before any @PostConstruct again

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

My question is:

Does this mean that all @Resource annotated methods on all beans in the context will be called before any @PostConstruct annotated methods are called? Or, in other words, can you call the beans @PostConstruct method after its dependencies have been introduced, even if the other beans in the context still did not contain nested dependencies?

Regards, Tim.

+6
java spring resources postconstruct lifecycle
source share
1 answer

It is guaranteed that when this bean @PostConstruct , all its @Resource fields will be entered. If any of these injections is beans themselves with their @Resource and @PostConstruct , then they will already be called. In other words, by the time any given @PostConstruct , it is guaranteed that all its dependencies are fully initialized.

It is possible and actually likely that BeanA will be constructed and initialized via @PostConstruct before BeanB even created if BeanB does not have a pronounced dependence on BeanA .

+9
source share

All Articles