Sobes.tech
Junior — Middle

Will the PostBeanProcessor be executed before calling methods annotated with @PostConstruct?

sobes.tech AI

Answer from AI

In the Spring Framework, methods annotated with @PostConstruct are called after all BeanPostProcessors have been applied to the bean, that is, after the bean post-processing stage.

The bean initialization process is approximately as follows:

  1. Creation of the bean instance.
  2. Dependency injection (DI).
  3. Calling BeanPostProcessor.postProcessBeforeInitialization methods.
  4. Calling methods annotated with @PostConstruct.
  5. Calling BeanPostProcessor.postProcessAfterInitialization methods.

Thus, PostBeanProcessor (if referring to BeanPostProcessor) executes before the @PostConstruct methods only in the part of postProcessBeforeInitialization. After @PostConstruct, postProcessAfterInitialization is called.

If "PostBeanProcessor" specifically refers to postProcessAfterInitialization, then it executes after @PostConstruct.

Will the PostBeanProcessor be executed before calling… - sobes.tech