首页 > 其他 > 详细

Bean后置处理器 BeanPostProcessor

时间:2017-11-17 11:32:36      阅读:290      评论:0      收藏:0      [点我收藏+]

1.BeanPostProcessor接口的作用

Bean后置处理器允许在调用初始化方法前后对Bean进行额外的处理,Bean后置处理器对IOC容器的所有bean实例逐一处理,而非单一实例。

我们可以定义一个或多个BeanPostProcessor接口实现类,然后注册到Spring IOC容器中。

2.BeanPostProcess接口的api

public interface BeanPostProcessor {

    /**
     * Apply this BeanPostProcessor to the given new bean instance <i>before</i> any bean
     * initialization callbacks (like InitializingBean‘s {@code afterPropertiesSet}
     * or a custom init-method). The bean will already be populated with property values.
     */
//实例化、依赖注入完毕,在调用显示的初始化之前完成一些定制的初始化任务
@Nullable default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } /** * Apply this BeanPostProcessor to the given new bean instance <i>after</i> any bean * initialization callbacks (like InitializingBean‘s {@code afterPropertiesSet} * or a custom init-method). The bean will already be populated with property values. */ //实例化、依赖注入、初始化完毕后执行
@Nullable
default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return bean; } }

 

Bean后置处理器 BeanPostProcessor

原文:http://www.cnblogs.com/whx7762/p/7850519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!