org.hibernate.LazyInitializationException: failed to lazily initialize no session or session was clo

1 篇文章 0 订阅
1 篇文章 0 订阅

ss2h整合中,出现了懒加载的错误,而且已经配置了openSessionInViewFilter,与ssh(struts1)不同,struts2不能随便配置过滤器,必须要放在指定的范围内

stutr1 中,怎么放基本都可以,但是在struts2中,openSessionInViewFilter过滤器一定要陪在 <filter-name>struts2</filter-name>之中,例如

webxml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   
     <!-- 配置struts2 -->
 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

   
    <!-- 指定spring的配置文件,默认从web根目录下寻找文件,通过从spring提供的classpath:前缀指定从类路径开始寻找 -->
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <!-- 即可以简单理解为tomcat初始化spring的applicationContext.xml 并放入类似request.setAttribute(...)中-->
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
  
  <!-- spring提供的过滤器 -->
  <filter>
  <filter-name>encoding</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
  <param-name>encoding</param-name>
  <param-value>UTF-8</param-value>
  </init-param>
  </filter>
 
  <filter-mapping>
  <filter-name>encoding</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 该过滤器作用类似于取消懒加载,会在需要关联时向数据库发送请求 -->
<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>/*</url-pattern> 

   </filter-mapping>

<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
   
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

注意最下面,<filter-name>openSessionInViewFilter</filter-name> 一定要被   <filter-name>struts2</filter-name>包住!!!否则,以struts1的老方法,可以让你调一壶的。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值