1 package org.test.InitializingBean; 2 3 import org.springframework.context.support.ClassPathxmlapplicationContext; 4 5 /** 6 * 測(cè)試 spring的 InitializingBean 接口 7 * @author Administrator 8 * 9 */10 public class InitializingBeanTest {11 12 /**13 * @param args14 */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 默認(rèn)的構(gòu)造函數(shù)執(zhí)行了");14 }15 16 @Override17 public void afterPropertiesSet() throws Exception {18 System.out.println(">>>>>>> 執(zhí)行了 afterPropertiesSet 方法");19 20 }21 22 }執(zhí)行的結(jié)果如下圖所示。可以看到當(dāng)執(zhí)行完User默認(rèn)的構(gòu)造函數(shù)之后,就會(huì)調(diào)用該類實(shí)現(xiàn)afterPropertiesSet方法

新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注