zoukankan      html  css  js  c++  java
  • Spring框架中InitializingBean执行顺序

     1 package org.test.InitializingBean;
     2 
     3 import org.springframework.context.support.ClassPathXmlApplicationContext;
     4 
     5 /**
     6  * 测试 spring的 InitializingBean 接口
     7  * @author Administrator
     8  *
     9  */
    10 public class InitializingBeanTest {
    11 
    12     /**
    13      * @param args
    14      */
    15     public static void main(String[] args) {
    16         
    17         ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml", 
    18                 InitializingBeanTest.class);
    19         ctx.start();
    20 
    21     }
    22 
    23 }
     1 package org.test.InitializingBean;
     2 
     3 import org.springframework.beans.factory.InitializingBean;
     4 
     5 /**
     6  * @see {@link org.springframework.beans.factory.InitializingBean#afterPropertiesSet}
     7  * @author Administrator
     8  *
     9  */
    10 public class User implements InitializingBean {
    11 
    12     public User() {
    13         System.out.println(">>>>>>> User 默认的构造函数执行了");
    14     }
    15         
    16     @Override
    17     public void afterPropertiesSet() throws Exception {
    18         System.out.println(">>>>>>> 执行了 afterPropertiesSet 方法");
    19 
    20     }
    21 
    22 }

    执行的结果如下图所示。可以看到当执行完User默认的构造函数之后,就会调用该类实现afterPropertiesSet方法

  • 相关阅读:
    美团面试(c++方向)
    浪潮面试-软开
    ofo C++面试
    B树、B+树等
    爱奇艺2017秋招笔试(C++智能设备方向)
    腾讯内推一面C++
    i++ 相比 ++i 哪个更高效?为什么?
    进程间的通讯(IPC)方式
    一台服务器能够支持多少TCP并发连接呢?
    可重入和不可重入
  • 原文地址:https://www.cnblogs.com/yql1986/p/4084888.html
Copyright © 2011-2022 走看看