Spring Bean Lifecycle with Executable Code

Lifecycle code example
Run the application and then stop it, the printed messages would show in console in the order as their number marks, which is exactly the same as lifecycle image shows:
BeanPostProcessor:
Note that in the above example, the method beforeInit
and afterInit
are achieved by implement BeanPostProcessor
. BeanPostProcessor
give us hooks into the Spring bean lifecycle to modify its configuration.