Hibernate出错 - could not initialize proxy - the owning Session was closed[zz]
分析原因:
由于Spring控制的Hibernate的生命周期只针对数据层和服务层,而未管理到表现层,所以会出现the owning Session was closed的现象。针对这一点,我通过hibernate filter的方式来解决。
解决方法:
在web.xml中配置filter来解决。
<!-- hibernate session filter -->
<filter>
<filter-name> hibernateFilter </filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name> hibernateFilter </filter-name>
<url-pattern> *.do </url-pattern>
</filter-mapping>
<filter>
<filter-name> hibernateFilter </filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name> hibernateFilter </filter-name>
<url-pattern> *.do </url-pattern>
</filter-mapping>
我们的系统架构是struts+spring+hibernate,struts跟spring的整合是在struts-config.xml里加了个plugin:
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath*:spring/**/*.xml" />
</plug-in>
在web.xml中配置hibernateFilter 后,还需要在struts-config.xml里把plugin去掉,在web.xml里加上如下代码:
<!--Spring ApplicationContext-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/**/*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
啦啦啦 我是救火的小行家 哪里有问题请找我呀 我喜欢来解决它

浙公网安备 33010602011771号