现在的位置: 首页 > 综合 > 正文

OpenSessionInView配置方法

2013年03月28日 ⁄ 综合 ⁄ 共 952字 ⁄ 字号 评论关闭

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,里面有很详细的说明

抱歉!评论已关闭.