spring中延迟关闭Session我在web.xml配置了
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- 加载Struts2控制器 -->
FilterDispatcher
org.apache.struts2.dispatcher.FilterDispatcher
<filter-mapping>
<filter-name>FilterDispatcher</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 将Hibernate的Session生命延长,为了解决由于Hibernate延迟加载,Session过早关闭问题 -->
<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>*.action</url-pattern>
</filter-mapping>
<!-- 加载Spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
index.jsp
然后 tomcat服务器就启动报错报下面的错
严重: Exception starting filter OpenSessionInViewFilter
java.lang.NoSuchFieldError: MANUAL
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.(OpenSessionInViewFilter.java:102)
望各位大哥大姐帮忙
[color=red]import org.hibernate.*;[/color]
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.filter.OncePerRequestFilter;
public class OpenSessionInViewFilter extends OncePerRequestFilter
{
public OpenSessionInViewFilter()
{
sessionFactoryBeanName = "sessionFactory";
singleSession = true;
[color=red]flushMode = FlushMode.MANUAL;[/color] }
我看了下 spring 源码! 找到了这个变量! 是hibernate的!
所以把你的hibernate 的包换一下绝对OK!
[url]http://forum.springsource.org/showthread.php?p=234756[/url]
换个版本、升下级试试
应该是 jar 包 版本不对! 换个新点的! spring 你现在的版本是多少呢?
很不巧 我的也是 spring 3.03
[code="java"]
opensession
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
flushMode
AUTO
singleSession
true
opensession
/*
[/code]
一切正常
不要找了 我知道了
将Hibernate升级为3.2看看
那都不要怀疑嘛! 我把[color=red]源码[/color]都给你拿出来了! 呵呵!
恰好我也是用的 spring 3.03 :wink: 再错了 我负责 呵呵