OpenSessionInView配置方法

web.xml

<filter>  
       
<filter-name>OpenSessionInViewFilter</filter-name>  
       
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
   
</filter>  
      
   
<filter-mapping>  
       
<filter-name>OpenSessionInViewFilter</filter-name>  
       
<url-pattern>/*</url-pattern>  
   
</filter-mapping>  
      
   
<listener>  
    
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>

struts-config.xml

<plug-in  
className="org.springframework.web.struts.ContextLoaderPlugIn">  
<set-property property="contextConfigLocation"  
value
="/WEB-INF/applicationContext.xml"/>  
</plug-in>

此處的org.springframework.web.struts.ContextLoaderPlugIn類裏的方法initWebApplicationContext(),在
getServletContext().setAttribute(attrName, wac);下增加一條屬性設置。
  getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

具體原因參考http://www.javaeye.com/topic/15057,裏面有很詳細的說明

發佈了21 篇原創文章 · 獲贊 1 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章