What is it for?

Execute a block of code for each and every bean that is initialised.

  • Bean Post Processor is a separate class
  • Spring executes the code in the Post Processor after initializing each and every bean


Print the Name of Every Bean that is Initialized


package com.skills421.examples.spring;

public class DisplayNameBeanPostProcessor implements BeanPostProcessor
public Object postProcessBeforeInitialization(Object bean, String beanName)
return bean;

public Object postProcessAfterInitialization(Object bean, String beanName)
System.out.println("Initialized Bean: "+beanName);
return bean;

Register the BeanPostProcessor with Spring


<bean class="com.skills421.examples.spring.DisplayNameBeanPostProcessor" />

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s