zoukankan      html  css  js  c++  java
  • init-method afterPropertiesSet BeanPostProcessor 执行顺序

    afterPropertiesSet方法,初始化bean的时候执行,可以针对某个具体的bean进行配置。afterPropertiesSet 必须实现 InitializingBean接口。实现 InitializingBean接口必须实现afterPropertiesSet方法。
    ————————————————
    版权声明:本文为CSDN博主「极客on之路」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u014756827/article/details/52369421

    在看用redis实现异步消息队列时,遇到了注册Event,其中看到了afterPropertiesSet。然后查博客,记录下。

    一、简单介绍

    1、init-method方法,初始化bean的时候执行,可以针对某个具体的bean进行配置。init-method需要在applicationContext.xml配置文档中bean的定义里头写明。例如:<bean id="TestBean" class="nju.software.xkxt.util.TestBean" init-method="init"></bean>
    这样,当TestBean在初始化的时候会执行TestBean中定义的init方法。
     
    2、afterPropertiesSet方法,初始化bean的时候执行,可以针对某个具体的bean进行配置。afterPropertiesSet 必须实现 InitializingBean接口。实现 InitializingBean接口必须实现afterPropertiesSet方法。
     
    3、BeanPostProcessor,针对所有Spring上下文中所有的bean,可以在配置文档applicationContext.xml中配置一个BeanPostProcessor,然后对所有的bean进行一个初始化之前和之后的代理。BeanPostProcessor接口中有两个方法: postProcessBeforeInitialization和postProcessAfterInitialization。 postProcessBeforeInitialization方法在bean初始化之前执行, postProcessAfterInitialization方法在bean初始化之后执行。
     
    总之,afterPropertiesSet 和init-method之间的执行顺序是afterPropertiesSet 先执行,init-method 后执行。从BeanPostProcessor的作用,可以看出最先执行的是postProcessBeforeInitialization,然后是afterPropertiesSet,然后是init-method,然后是postProcessAfterInitialization。
    ————————————————
    版权声明:本文为CSDN博主「零点-一条路走到底」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u013013553/article/details/79038702

  • 相关阅读:
    POJ 1061
    hihocoder 1330
    HDU 1525
    UVALive 3938
    POJ 2528
    HDU 1754
    《ACM-ICPC程序设计系列 数论及其应用》例题个人答案记录
    URAL 1277
    HDU 3746
    HDU 2087
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/12160472.html
Copyright © 2011-2022 走看看