Sun
          是選擇你愛的人還是愛你的人?
          posts - 8,comments - 14,trackbacks - 0
          org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderListener

          是視圖層加載sping的兩種方式。
          那么這兩種方式誰的優先級高,從容器加載程度上看,是org.springframework.web.context.ContextLoaderListener

          那么中方式都被配置在項目中,會使用哪個一個呢?
          答案是org.springframework.web.struts.ContextLoaderPlugIn

          當然如果你不需要在視圖層采用lazy而配置org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
          那么你可以兩個都配置。
          但如果你需要使用,那就會。

          我們知道,容器初始化Spring配置文件時,使用getServletContext().setAttribute方法key,value全局保存。
          那么當你使用OpenSessionInViewFilter時,他取得的是哪個呢?

          其實OpenSessionInViewFilter是sping的Filter,它采用WebApplicationContextUtils的方式獲得WebApplicationContext
          ,但它并不能加載由struts-config.xml文件ContextLoaderPlugIn提供初始化的上下文。

          如果你需要在視圖層加載一對對....等關聯對象。那么就會有
          could not initialize proxy - the owning Session was closed
          錯誤。
          到此處我們看到,sping在應用程序和OpenSessionInViewFilter之間,加載了不同的上下文。
          我們知道OpenSessionInViewFilter下無法獲得ContextLoaderPlugIn加載的上下文,那我們可以推算,
          應用程序應該加載了ContextLoaderPlugIn上下文,而OpenSessionInViewFilter卻加載了ContextLoaderListener的上下文。
          才導致視圖層session有關閉的問題。

          嘗試解決此問題,若你配置了兩個,則刪除ContextLoaderPlugIn的加載方式。
          若你只配置了ContextLoaderPlugIn的加載方式,則改成ContextLoaderListener加載方式。

          原創文章,轉載請注明出處。
          http://www.aygfsteel.com/beijing2008/articles/317973.html








          posted on 2010-04-11 02:24 .Sun 閱讀(3832) 評論(1)  編輯  收藏

          FeedBack:
          # re: org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderListener
          2010-04-12 11:19 | 匿名用戶
          AI,原來是這個問題。
          看了
          明白了許多。
          不過博主沒說為什么不能讀取呢。  回復  更多評論
            

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


          網站導航:
           
          主站蜘蛛池模板: 松江区| 沈丘县| 冕宁县| 台北市| 溆浦县| 垣曲县| 舟山市| 始兴县| 洛隆县| 曲松县| 洛川县| 大同县| 九龙城区| 蓬莱市| 南昌市| 吉安市| 庄河市| 格尔木市| 天津市| 墨脱县| 安阳县| 东乌珠穆沁旗| 汽车| 镇雄县| 长沙县| 察雅县| 崇明县| 喀什市| 平潭县| 浦县| 凤山市| 古丈县| 苗栗县| 普陀区| 武夷山市| 枣阳市| 宜宾市| 成都市| 仲巴县| 迭部县| 日土县|