BeanPostProcessor 接口

public interface BeanPostProcessor {

	Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;

	Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;

}

 

BeanPostProcessor 接口: 初始化bean前后对BeanPostProcessor实现类进行回调

 

与InitializingBean和DisposableBean接口不同的是:

  • BeanPostProcessor接口将对所有的bean都起作用,即所有的bean初始化前后都会回调BeanPostProcessor实现类
  • InitializingBean和DisposableBean接口是针对单个bean的,即只有在对应的bean实现了InitializingBean或DisposableBean接口才会对其进行回调

 

细节:

BeanPostProcessor接口中定义了两个方法,

  • postProcessBeforeInitialization()

    在一个bean被完全初始化前进行回调,此时对应的bean已经实例化了,但是对应的属性注入等还没有进行,

         即在调用InitializingBean的afterPropertiesSet()方法或bean对应的init-method之前。

 

  • postProcessAfterInitialization()

        将在bean被完全初始化后进行回调,此时对应的依赖注入已经完成,

        即在调用InitializingBean的afterPropertiesSet()方法或对应init-method方法之后。

 

 

摘自:http://blog.csdn.net/elim168/article/details/76146351

posted on 2017-12-22 21:27  HB1  阅读(103)  评论(0)    收藏  举报

导航