How a Spring BeanPostProcessor works

The following sequence diagram taken from Getting started with Spring Framework shows how Spring's BeanPostProcessor works:

The above diagram shows that when an instance of Spring container is created, MyBeanPostProcessor (a BeanPostProcessor implementation) is created before any regular Spring bean (like ABean) is created. When an ABean instance is created, it is passed to MyBeanPostProcessor's postProcessBeforeInitialization and postProcessAfterInitialization methods. Notice that MyBeanPostProcessor's postProcessBeforeInitialization is invoked before ABean's init method is invoked, and MyBeanPostProcessor's postProcessAfterInitialization is invoked after ABean's init method is invoked.  You can use postProcessBeforeInitialization and postProcessAfterInitialization methods to make modifications to the ABean instance.

Comments

Popular posts from this blog

Getting started with Spring Framework, Second Edition now available