码迷,mamicode.com
首页 > 其他好文 > 详细

Bean后置处理器 BeanPostProcessor

时间:2017-11-17 11:59:02      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:property   pop   ati   processor   llb   bsp   显示   val   obj   

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

标签:property   pop   ati   processor   llb   bsp   显示   val   obj   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!