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.
It is guaranteed that when a given bean’s
@PostConstructgets called, that all of its@Resourcefields will have been injected. If any of those injections are themselves beans with their own@Resourceand@PostConstruct, then those will have already been called. In other words, by the time any given@PostConstructis called, it is guaranteed that all of its dependencies have been fully initialized.It is possible, and in fact likely, that
BeanAwill be constructed and initialized via@PostConstructbeforeBeanBhas even been instantiated, ifBeanBhas no expressed dependency onBeanA.