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

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

          那么中方式都被配置在項(xiàng)目中,會(huì)使用哪個(gè)一個(gè)呢?
          答案是org.springframework.web.struts.ContextLoaderPlugIn

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

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

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

          如果你需要在視圖層加載一對(duì)對(duì)....等關(guān)聯(lián)對(duì)象。那么就會(huì)有
          could not initialize proxy - the owning Session was closed
          錯(cuò)誤。
          到此處我們看到,sping在應(yīng)用程序和OpenSessionInViewFilter之間,加載了不同的上下文。
          我們知道OpenSessionInViewFilter下無(wú)法獲得ContextLoaderPlugIn加載的上下文,那我們可以推算,
          應(yīng)用程序應(yīng)該加載了ContextLoaderPlugIn上下文,而OpenSessionInViewFilter卻加載了ContextLoaderListener的上下文。
          才導(dǎo)致視圖層session有關(guān)閉的問(wèn)題。

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

          原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處。
          http://www.aygfsteel.com/beijing2008/articles/317973.html








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

          FeedBack:
          # re: org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderListener
          2010-04-12 11:19 | 匿名用戶
          AI,原來(lái)是這個(gè)問(wèn)題。
          看了
          明白了許多。
          不過(guò)博主沒(méi)說(shuō)為什么不能讀取呢。  回復(fù)  更多評(píng)論
            

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 洞头县| 桃园县| 句容市| 天长市| 康保县| 浦城县| 伊宁县| 丰城市| 资兴市| 塔城市| 崇阳县| 北川| 云浮市| 湟中县| 八宿县| 镇雄县| 微博| 宝鸡市| 乐都县| 新郑市| 绩溪县| 新河县| 中超| 四川省| 清丰县| 广灵县| 江川县| 古田县| 米泉市| 榆林市| 贵溪市| 清镇市| 成安县| 怀远县| 来宾市| 景洪市| 马关县| 特克斯县| 山西省| 喀喇沁旗| 上高县|