Atea - Hero's Grave

          面向?qū)ο螅_源,框架,敏捷,云計(jì)算,NoSQL,商業(yè)智能,編程思想。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            40 隨筆 :: 0 文章 :: 28 評(píng)論 :: 0 Trackbacks
          struts2 Action里面的getter方法會(huì)在Action結(jié)束后被自動(dòng)調(diào)用,例如有此情況:
          <package extends="struts-default">
          <action name="MyAction">
          <action name="AnotherAction" method="getSomething">
          ...
          在Action中
              public String execute(){
                  System.out.println(
          "execute");
                 
          return SUCCESS;
              }
              
          public String getA() {
                  System.out.println(
          "getA");
                  
          return SUCCESS;
              }
              
          public String geta() {
                  System.out.println(
          "geta");
                  
          return SUCCESS;
              }
              
          public String getaa() {
                  System.out.println(
          "getaa");
                  
          return SUCCESS;
              }
              
          public String getaA() {
                  System.out.println(
          "getaA");
                  
          return SUCCESS;
              }
              
          public String getB() {
                  System.out.println(
          "getB");
                  
          return SUCCESS;
              }
              
          public String gotA() {
                  System.out.println(
          "gotA");
                  
          return SUCCESS;
              }
          當(dāng)調(diào)用MyAction的時(shí)候,輸出結(jié)果為:
          execute
          geta
          getaA
          getaa
          getB

          也就是說,即使你沒有調(diào)用AnotherAction,getSomething仍然會(huì)執(zhí)行。

          ---------------------------------------------------------------------------

          090520更新

          這個(gè)問題確實(shí)很惱人,這兩天又被此事折騰的崩潰。
          再次提醒,在struts2的Action中慎起get打頭的函數(shù)!

          出錯(cuò)的整個(gè)過程是這樣的(錯(cuò)的花了..):
          在測(cè)試程序的過程中,發(fā)現(xiàn)后臺(tái)Hibernate不時(shí)的發(fā)生讀取臟數(shù)據(jù)的情況。
          為此專門編寫了測(cè)試文件進(jìn)行測(cè)試,并沒有發(fā)現(xiàn)讀取臟數(shù)據(jù)的現(xiàn)象。眾所周知Session不是線程安全的,可系統(tǒng)是用ThreadLocal來管理Session的,按說不應(yīng)該出現(xiàn)這個(gè)問題。
          我也曾懷疑過是sf緩存出的錯(cuò),可去掉緩存后還是有問題。

          在打開了Session創(chuàng)建和銷毀的Log后,發(fā)現(xiàn)程序在Action返回后,又創(chuàng)建了新的Session(沒有關(guān)閉)。
          注:系統(tǒng)在Action層對(duì)Service層做了IOC,在Service層對(duì)DAO層做了IOC。
          結(jié)果就是,Action結(jié)束時(shí)調(diào)用了getXXXService函數(shù),而又神奇的調(diào)到了當(dāng)前Service所有g(shù)et打頭的函數(shù)。

          最后的解決辦法是,此處的IOC并不需要getter,把getter刪除就行了。
          posted on 2009-02-16 20:09 Atea 閱讀(389) 評(píng)論(0)  編輯  收藏 所屬分類: Struts

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 固镇县| 锦屏县| 综艺| 汉阴县| 上虞市| 襄樊市| 商南县| 旬邑县| 西和县| 莱州市| 邵阳县| 宜兰县| 石家庄市| 河间市| 宾川县| 潜江市| 静海县| 城口县| 淳安县| 察雅县| 姜堰市| 南川市| 南和县| 随州市| 高雄县| 卢龙县| 清丰县| 富源县| 平利县| 博客| 黔西| 山东| 勃利县| 象山县| 陆河县| 随州市| 法库县| 额尔古纳市| 辽宁省| 托里县| 花垣县|