spring+struts+hibernate OpenSessionInView 配置学习

本文介绍如何在Spring、Struts和Hibernate框架下配置OpenSessionInView,包括正确的配置步骤和注意事项,避免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将失效。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值