java學(xué)習(xí)

          java學(xué)習(xí)

           

          spring bean 初始化方法和銷毀方法的配置

          三種初始化方式
          public class Cat {
          @PostConstruct//初始化
          public void afterPropertiesSet() throws Exception {
          System.out.println(" cat init");
          }
          @PreDestroy//銷毀
          public void destroy() throws Exception {
          System.out.println("cat destroy");
          }
          }
          public class User implements InitializingBean,DisposableBean{
          public String toString() {
          return "444";
          }
          @Override//初始化
          public void afterPropertiesSet() throws Exception {
          System.out.println(" user afterPropertiesSet");
          }
          @Override//銷毀
          public void destroy() throws Exception {
          System.out.println("user destroy");
          }
          }
          public class Room {
                  //初始化
          public void afterPropertiesSet() throws Exception {
          System.out.println(" room afterPropertiesSet");
          }
                  //銷毀
          public void destroy() throws Exception {
          System.out.println("room destroy");
          }
          }
          @Configuration
          public class Cfg1 {
          @Bean
          public Cat getCat() {
          return new Cat();
          }
          @Bean
          public User getUser() {
          return new User();
          }
          @Bean(initMethod="afterPropertiesSet",destroyMethod="destroy")
          public Room getRoom() {
          return new Room();
          }
          }

          posted on 2018-03-06 13:56 楊軍威 閱讀(239) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 读书| 德钦县| 府谷县| 车致| 若羌县| 龙游县| 贵阳市| 普洱| 磴口县| 抚宁县| 上犹县| 治多县| 长宁区| 项城市| 天全县| 遂宁市| 三穗县| 松潘县| 获嘉县| 漯河市| 克什克腾旗| 徐闻县| 晋江市| 女性| 湟源县| 应城市| 北碚区| 洞头县| 麦盖提县| 策勒县| 灵山县| 阿拉善盟| 读书| 湘潭县| 新晃| 章丘市| 平果县| 秦皇岛市| 永川市| 东兰县| 遂宁市|