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:
- Creation of the bean instance.
- Dependency injection (DI).
- Calling
BeanPostProcessor.postProcessBeforeInitializationmethods. - Calling methods annotated with
@PostConstruct. - Calling
BeanPostProcessor.postProcessAfterInitializationmethods.
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.