Home Tutorial Spring Spring3 Ioc Spring Bean Post Processor


Share on Google+Share on Google+
Spring Bean Post Processor
Posted on: September 6, 2010 at 12:00 AM
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.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;

public class AppMain {

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


<beans xmlns="http://www.springframework.org/schema/beans"
  <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


Related Tags for Spring Bean Post Processor:

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.

Posted on: September 6, 2010

Recommend the tutorial

Advertisements Advertisements