zoukankan      html  css  js  c++  java
  • spring IoC (五)BeanPostProcessor

    参考 Spring IoC (二)实例化、初始化

      BeanPostProcessor是使用IoC容器时经常会遇到的一个特性,这个Bean的后置处理器是一个监听器,它

    可以监听容器触发的事件。将它向IoC容器注册后,容器中管理的Bean具备了接受IoC容器事件回调的能力。

    BeanPostProcessor接口

     1 public interface BeanPostProcessor {
     2 
     3     /**
     4      * Apply this BeanPostProcessor to the given new bean instance <i>before</i> any bean
     5      * initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
     6      * or a custom init-method). The bean will already be populated with property values.
     7      * The returned bean instance may be a wrapper around the original.
     8      * @param bean the new bean instance
     9      * @param beanName the name of the bean
    10      * @return the bean instance to use, either the original or a wrapped one; if
    11      * {@code null}, no subsequent BeanPostProcessors will be invoked
    12      * @throws org.springframework.beans.BeansException in case of errors
    13      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
    14      */
    15     Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;
    16 
    17     /**
    18      * Apply this BeanPostProcessor to the given new bean instance <i>after</i> any bean
    19      * initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
    20      * or a custom init-method). The bean will already be populated with property values.
    21      * The returned bean instance may be a wrapper around the original.
    22      * <p>In case of a FactoryBean, this callback will be invoked for both the FactoryBean
    23      * instance and the objects created by the FactoryBean (as of Spring 2.0). The
    24      * post-processor can decide whether to apply to either the FactoryBean or created
    25      * objects or both through corresponding {@code bean instanceof FactoryBean} checks.
    26      * <p>This callback will also be invoked after a short-circuiting triggered by a
    27      * {@link InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation} method,
    28      * in contrast to all other BeanPostProcessor callbacks.
    29      * @param bean the new bean instance
    30      * @param beanName the name of the bean
    31      * @return the bean instance to use, either the original or a wrapped one; if
    32      * {@code null}, no subsequent BeanPostProcessors will be invoked
    33      * @throws org.springframework.beans.BeansException in case of errors
    34      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
    35      * @see org.springframework.beans.factory.FactoryBean
    36      */
    37     Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;
    38 
    39 }

    流程图

    通过populateBean方法和 initializeBean调用

  • 相关阅读:
    不能初始化ps2020,因为意外的遇到文件尾
    关于在云服务器上邮箱等功能无法正常的解决方法|phpcmsv9
    WAMP环境配置|apache24配置|php7配置|MySQL8配置
    SAP(ABAP) ABAP内部外部数据转换常用function
    移动平台对 META 标签的定义
    JavaScript/Jquery:Validform 验证表单的相关属性解释
    android开发问题 Failed to pull selection 菜鸟记录
    下载android sdk更新包离线安装解决方案
    android:inputType常用取值
    访问IIS元数据库失败解决方法
  • 原文地址:https://www.cnblogs.com/toUpdating/p/9728480.html
Copyright © 2011-2022 走看看