Java Tutorial/Spring/BeanPostProcessor
Версия от 17:44, 31 мая 2010; (обсуждение)
Implements BeanPostProcessor
File: Main.java
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
ctx.getBean("w");
}
}
class BeanInitializationLogger 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("Bean "" + beanName + "" initialized");
return bean;
}
}