生命周期-BeanPostProcessor-后置处理器

Posted ayasatomayoi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生命周期-BeanPostProcessor-后置处理器相关的知识,希望对你有一定的参考价值。

通过实现BeanPostProcessor-后置处理器接口来实现bean在执行初始化方法(此时bean的属性已被赋值)前后的处理工作。

public class MyBeanPostProcessor implements BeanPostProcessor {

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization......"+ bean +"==>" + beanName);
        return bean;
    }

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

        System.out.println("postProcessAfterInitialization...... "+ bean +"==>" + beanName);
        return bean;
    }
}
postProcessBeforeInitialization.....[email protected]6166e06f==>org.springframework.context.event.internalEventListenerProcessor
postProcessAfterInitialization...... [email protected]6166e06f==>org.springframework.context.event.internalEventListenerProcessor
postProcessBeforeInitialization....[email protected]1c72da34==>org.springframework.context.event.internalEventListenerFactory
postProcessAfterInitialization...... [email protected]72da34==>org.springframework.context.event.internalEventListenerFactory
postProcessBeforeInitialization......com.yy[email protected]6e38921c==>mainConfigOfLifeCycle
postProcessAfterInitialization...... com.yyc.config.MainConfigOfLifeCycle$$EnhancerBySpringCG[email protected]==>mainConfigOfLifeCycle
car construct ....
[email protected]==>car
init method
postProcessAfterInitialization...... [email protected]==>car
容器创建完成
五月 24, 2019 3:24:34 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext doClose
信息: Closing org.spring[email protected]4141d797: startup date [Fri May 24 15:24:34 CST 2019]; root of context hierarchy
destroy method

 

以上是关于生命周期-BeanPostProcessor-后置处理器的主要内容,如果未能解决你的问题,请参考以下文章

spring IOC 容器中 Bean 的生命周期

Spring的后置处理器

Spring IOC容器生命周期阶段总结

IOC容器中bean的生命周期(简化)

Spring生命周期-BeanFactoryPostProcessor和BeanPostProcessor

八spring生命之器之BeanPostProcessor