他们说使用 ajax 在 hibernate 和 webapp 中关闭会话是 java 和 spring 的常见问题,所以我必须像这样在 web.xml 中设置 OpenSessionInViewInFilter
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<filter>
<filter-name>springFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springFilter</filter-name>
<url-pattern>/dwr/*</url-pattern>
</filter-mapping>
但即便如此,当我尝试使用 Hibernate Criteria api 时,我得到“会话已关闭”休眠异常,所以我尝试了另一种使用 OpenSessioninViewInterceptor 的弹簧方式
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="false"/>
<property name="mappings">
<props>
<prop key="*">dwrController</prop>
</props>
</property>
<property name="interceptors">
和拦截器
<bean id="openSessionInViewInterceptor"class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
同样的“会话已关闭”问题。请在这里帮助我。我是 Java 新手,非常感谢您的帮助。
我目前在 maven 的 jetty 插件中运行,版本 6.1.10。