java學習

          java學習

           

          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 楊軍威 閱讀(238) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 尉犁县| 和平区| 石台县| 海原县| 兰州市| 明光市| 曲靖市| 文化| 岳阳县| 宣武区| 辽源市| 项城市| 城口县| 华坪县| 东莞市| 铜川市| 白玉县| 清远市| 安吉县| 肥城市| 泰来县| 乌兰察布市| 蒙城县| 葵青区| 凉山| 独山县| 翁源县| 辽宁省| 清镇市| 花垣县| 黄大仙区| 瑞金市| 临漳县| 柳江县| 泾阳县| 西城区| 佛教| 永吉县| 巨野县| 卢氏县| 柳江县|