Spring gives you a lot of mail processors, not just BeanPostProcessor . In addition, most of them are used by Spring itself. The one you mentioned in this question is used (as indicated in its title) to publish the bean process after it is created. Spring container behavior is as follows:
- Spring creates a bean call to its constructor
postProcessBeforeInitialization(Object bean, String beanName) is called
- bean initialization process:
@PostConstruct , afterPropertiesSet() (defined by the InitializingBean callback interface), a custom init method
postProcessAfterInitialization(Object bean, String beanName) is called
At first glance, this may look complicated and overwhelming, but when you create complex applications on top of Spring, all these functions are simply invaluable.
Possible scenarios, for example (taken from Spring itself):
AutowiredAnnotationBeanPostProcessor - AutowiredAnnotationBeanPostProcessor bean looking for @Autowire annotation to perform dependency injectionRequiredAnnotationBeanPostProcessor - Checks if all dependencies are marked as @Required .ServletContextAwareProcessor - injects ServletContext into beans implementation of the ServletContextAware interface- in fact, initialization / descriptive callbacks such as JSR-250
@PostConstruct and @PreDestroy are implemented using a post processor: CommonAnnotationBeanPostProcessor
Of course, all the mentioned post-processors should be executed in a certain order, but Spring is responsible for this.
Piotr de
source share