In this tutorial you will learn about Spring Bean Post Processor.
In this tutorial you will learn about 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.
StudentBean.java
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; } }
AppMain.java
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( "context.xml"); context.getBean("student"); } }
context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
|
Initialized Bean : student |