码迷,mamicode.com
首页 > 编程语言 > 详细

Spring框架中InitializingBean执行顺序

时间:2018-01-18 18:00:41      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:span   int   复制   copy   tor   logs   row   factory   log   

本文转自:https://www.cnblogs.com/yql1986/p/4084888.html

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方法

 

技术分享图片

Spring框架中InitializingBean执行顺序

标签:span   int   复制   copy   tor   logs   row   factory   log   

原文地址:https://www.cnblogs.com/520playboy/p/8311457.html

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