`
laukin
  • 浏览: 5638 次
  • 性别: Icon_minigender_1
  • 来自: 西安
文章分类
社区版块
存档分类
最新评论

spring+struts+hibernate OpenSessionInView 配置学习

阅读更多

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将失效。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics