论坛首页 Java企业应用论坛

spring+struts+hibernate OpenSessionInView 配置学习

浏览 4546 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-07-21  

spring+struts+hibernate OpenSessionInView 配置学习

在web.xml中使用OpenSessionInView不能配置:

xml 代码
  1. <servlet>      
  2.     <servlet-name>contextservlet-name>      
  3.     <servlet-class>  
  4.             org.springframework.web.context.ContextLoaderServlet   
  5.     servlet-class>      
  6.     <load-on-startup>1load-on-startup>      
  7. servlet>   

需要配置 org.springframework.web.context.ContextLoaderListener:

xml 代码
  1. <listener>        
  2.     <listener-class>  
  3.         org.springframework.web.context.ContextLoaderListener   
  4.     listener-class>        
  5. listener>    

并且需要配置 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter   

xml 代码
  1. <filter>  
  2.     <filter-name>OpenSessionInViewfilter-name>  
  3.     <filter-class>  
  4.         org.springframework.orm.hibernate3.support.OpenSessionInViewFilter   
  5.     filter-class>  
  6.     <init-param>  
  7.         <param-name>singleSessionparam-name>  
  8.         <param-value>trueparam-value>  
  9.     init-param>  
  10. filter>  

 格外注意:

在配置struts-config.xml文件时,为了整合spring ,需要配置plugin:

xml 代码
  1. <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">  
  2.     <set-property property="contextConfigLocation" 
  3.                      value="/WEB-INF/classes/action- servlet.xml"/>  
  4. plug-in>  

 

具体见:http://www.iteye.com/topic/15057

但是,指定contextConfigLocation属性时, 只需要将配置strutsAction部分的spring配置文件引入,不能将配置数据源和事务管理的配置文件引入,否则OpenSessionInView将失效。
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics