转载

spring 在每个类初始化的前后调用的方法

@Component

public class MyBeanPostProcessor implements BeanPostProcessor{

//在每个bean初始化后,初始化方法执行后,都执行

的方法

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

System.out.println("postProcessAfterInitialization=="+beanName);

return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);

//在每个bean初始化后,在初始化方法执行前,都执行的方法

@Override

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

System.out.println("postProcessBeforeInitialization=="+beanName);

return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);

}

原文  http://www.blogjava.net/yangjunwei/archive/2018/03/06/433080.html
正文到此结束
Loading...