@PostConstruct annotation and spring lifecycle

If you are asking is injection of given class happening after @PostConstruct in that bean is called, then the answer is yes – @PostConstruct is executed before bean is considered as “injectable”

If you are asking if @PostConstruct on given bean is executed after all injections has been done (on the same bean) – then yes – @PostConstruct is executed after injections are commited to given bean. This is the reason it exists. Normally you could put @PostConstruct actions into the constructor. However, when new object is created (constructor is called) injections are not performed yet – so any initialization that depends on injected objects would fail due to NPE. That is why you need @PostConstruct

Leave a Comment