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

Example

Print the Name of Every Bean that is Initialized

DisplayNameBeanPostProcessor

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

Spring.xml

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

Leave a comment

Skills421

Welcome to Skills421, our knowledge repository for all things tech in the 21st century

Let’s connect

Search