隨筆-26  評論-44  文章-20  trackbacks-0
          public class Table {
              String tableName;
              String mainPropertyName;
              static int count=1;
              static DBExcute dbExcute=(DBExcute)new ClassPathXmlApplicationContext("applicationContext.xml").getBean("dbExcute");
             
              Table(String tableName,String mainPropertyName){
                  this.tableName=tableName;
                  this.mainPropertyName=mainPropertyName;
                  System.out.println("construct table"+(count++)+" use:"+dbExcute);
              }
                  .............
                  .............
               public static void main(String []dsf){
               new Table("user","1");
            }
          }

          如上只new Table(..)一次:
          結果卻是:
          construct table1 use:null
          construct table2 use:null
          construct table3 use:null
          construct table4 use:null
          construct table5 use:null
          construct table6 use:com.yijia_ctgu.DB.DBExcute@535b58


          奇怪中。。。。。。。


          明白了,spring容器初始化的時候,初始化dbDAO bean會生成五個table,可能是先初始化,后才賦值給dbExcute,所以剛開始的五個都是null.

          posted on 2008-11-05 14:45 開機 閱讀(277) 評論(1)  編輯  收藏

          評論:
          # re: 為何new了一次,卻執行了好幾次? 2008-11-18 18:40 | eyejava
          工廠ApplicationContext會提前在容器中初使化一些實例,但用戶使用時,再從容器中取一個給用戶。  回復  更多評論
            

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


          網站導航:
           
          主站蜘蛛池模板: 鄂托克前旗| 香港| 大新县| 晋江市| 旺苍县| 重庆市| 化州市| 栾川县| 镶黄旗| 永平县| 铁力市| 会理县| 屏东市| 五大连池市| 游戏| 当涂县| 义马市| 琼海市| 博爱县| 深圳市| 五华县| 华亭县| 长阳| 靖边县| 如东县| 名山县| 察雅县| 贵港市| 岳阳市| 甘肃省| 石城县| 正宁县| 自贡市| 佳木斯市| 彭阳县| 利津县| 天全县| 青龙| 芷江| 东辽县| 丰都县|