隨筆-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(..)一次:
          結(jié)果卻是:
          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了一次,卻執(zhí)行了好幾次? 2008-11-18 18:40 | eyejava
          工廠ApplicationContext會提前在容器中初使化一些實例,但用戶使用時,再從容器中取一個給用戶。  回復(fù)  更多評論
            

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 双城市| 六枝特区| 沭阳县| 新晃| 凤冈县| 榆树市| 达州市| 永康市| 安岳县| 海林市| 桐乡市| 鲁山县| 遵义县| 民乐县| 石屏县| 息烽县| 剑河县| 肇庆市| 靖宇县| 邹城市| 洞头县| 吉木乃县| 扎囊县| 忻城县| 徐汇区| 永川市| 阳春市| 镶黄旗| 黔江区| 道真| 徐州市| 弥渡县| 林甸县| 新兴县| 三原县| 高邑县| 图们市| 建平县| 苏州市| 通河县| 北川|