Share on Google+Share on Google+

Spring Bean Post Processor

In this tutorial you will learn about Spring Bean Post Processor.

Spring Bean Post Processor

The interface BeanPostProcessor allows custom modification of all new bean instance like for example making for marker interfaces or wrapping them with all proxies. The advance of interface BeanPostProcessor is that it auto-detect BeanPostProcessor beans in their bean definations and apply all beans before any others get created.

package com.roseindia.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

class StudentBean implements BeanPostProcessor {

	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;

	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {

		System.out.println("Initialized Bean : " + beanName);
		return bean;

package com.roseindia.common;

import org.springframework.context.ApplicationContext;

public class AppMain {

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(


<beans xmlns=""
  <bean id="student" class="java.lang.String">
  <bean id="studentBean" class="com.roseindia.common.StudentBean" />

When you run this application it will display message as shown below:

Initialized Bean : student

Download this example code


Posted on: September 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.