Java Login


Hello guys, is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.

     << Previous
Next >>     

Bean Factory Post Processor

BeanFactoryPostProcessor in spring belongs to the package org.springframework.beans.factory.config. BeanFactoryPostProcessor is used to work on bean configuration metadata. BeanFactoryPostProcessor can change bean configuration metadata potentially. It happens before other bean is initialized by spring container. In spring, more than one BeanFactoryPostProcessor can be used and their order of execution can be set by order attribute.

Extension of BeanPostProcessor is BeanFactoryPostProcessor interface which allows direct modification of bean definitions before a bean is instantiated

An ApplicationContext will automatically register and process a bean that implements either of these interfaces, but a BeanFactory would have to have a BeanPostProcessor or BeanFactoryPostProcessor registered with it programatically.

A BeanFactoryPostProcessor lets you modify the actual bean definition instead of the instance as it's created. The PropertyResourceConfigurer and PropertyPlaceholderConfigurer are two very useful BeanFactoryPostProcessors. They let you put placeholders as property values that are then replaced with values from property file. This is very useful for configuring a database connection pool, mail server, etc. Here is some class which used BeanFactoryPostProcessor

  • AspectJWeavingEnabler
  • CustomAutowireConfigurer
  • CustomScopeConfigurer
  • PropertyOverrideConfigurer
  • PropertyPlaceholderConfigurer
  • PropertyResourceConfigurer
  • ServletContextPropertyPlaceholderConfigurer

package beanPostProcessor;

public class Employee {
private String name;

public String getName() {
return name;

public void setName(String name) {
this .name = name;

public void init() {
System.out.println("Bean init method called ");

public void destroy() {
System.out.println("Bean destroy method called ");

package beanPostProcessor;

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

public class Util implements BeanFactoryPostProcessor {

public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory)
throws BeansException {

System.out.println("My Bean Factory Post Processor called");


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

<bean id="employee" class="beanPostProcessor.Employee"
init-method="init" destroy-method="destroy" >
<property name="name" value="Test"/>

<bean> class="beanPostProcessor.Util"/>


package beanPostProcessor;


public class Main {
public static void main(String[] args) {

AbstractApplicationContext context = new

Employee obj = (Employee) context.getBean("employee");

     << Previous
Next >>