想解决问题:spring中session管理opersession,避免页面中数据未输出完session就被关闭了(session延迟加载)
转载:
Spring+Hibernate中OpenSessionInView模式运用配置OpenSessionInView模式也很简单,Spring提供了两种方式:
1、过滤流Filter
<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>*.do</url-pattern>
</filter-mapping>
2、Interceptor
<!-- SimpleUrlHandlerMapping -->
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors" ref="openSessionInViewInterceptor"/>
<property name="mappings">
<props>
。。。
</props>
</property>
</bean>
<!-- =========== openSessionInViewInterceptor ==============-->
<bean id="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
推荐用第二种方式
但尝试使用时发现,第一种方法看似简单,加入到代码中总是报错。
按上面所说方法,加在web.xml中后,在最上面加着。报错:java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
在网上搜索,提示:需要在web.xml中加入
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
加上之后直接启动报错了。。
main FATAL - Proxool Provider unable to load JAXP configurator file: proxool.xml
org.logicalcobwebs.proxool.ProxoolException: Parsing failed.
Caused by: org.logicalcobwebs.proxool.ProxoolException: Attempt to register duplicate pool called 'dbpool'
再经查询说需要在web.xml中加入如下:
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔此参数用于后面的Spring-Context loader -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value>
</context-param>
第二种方法,感觉说的不是很明确。
大家有没有使用过的,能告知具体如何处理,谢谢!(在网上找了好久,都是这个,可是感觉不知道如何用。)
补充:昨天新试第一种方法,只需在web.xml中加入即可,并注意注释掉struts-conf.xml中的如下部分。
web.xml中加入:
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
struts-conf。xml中需注释内容:
<!--
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
-->
分享到:
相关推荐
介绍Spring+hibernate opensessioninview问题
为了练手培训,给大家准备的 Open Session In View 的简单例子,纯代码,大家可以参考,其中主要说了六部分内容: 1.通过接口编程 2.通过spring注入dao到 action 3.通过 open session in view filter 支持 延迟加载...
OpenSessionInView项目整合jar包
Spring提供的CharacterEncoding和OpenSessionInView功能
在没有使用Spring提供的Open Session In View情况下,因需要在service(or Dao)层里把session关闭,所以lazy loading 为true的话,要在应用层内把关系集合都初始化,如 company.getEmployees(),否则Hibernate抛...
SSH项目整合示例【OpenSessionInView】所用到的jar包 包含Struts + Hibernate + Spring所有jar及其依赖的jar
NULL 博文链接:https://8366.iteye.com/blog/472141
NULL 博文链接:https://likenice.iteye.com/blog/290162
NULL 博文链接:https://yanzhenwei.iteye.com/blog/1701164
和Spring中OpenSessionInView由于org.springframework.web.struts.ContextLoaderPlugIn中保存同一个对象的名不同导致openSessionInView失效 稍微修改后在struts-config.xml中使用MyContextLoaderPlugIn.jar包中...
SSH项目整合示例【OpenSessionInView】源码
最新版SSH项目整合 实现了OpenSessionInView。 hibernate5.2.3+struts2.5.2+spring4.3.3
3,在web.xml中配置 spring 的 OpenSessionInView 过滤器(解决抛LazyInitializationException的问题) 1,配置 <!-- 配置 spring 的 OpenSessionInView 过滤器 --> <filter-name>OpenSessionInView ...
spring2.5学习PPT 传智博客 01_全面阐释Spring及其各项功能 ... 30.Spring提供的CharacterEncoding和OpenSessionInView功能 31.使用Spring集成JPA 32.Struts+Spring+JPA集成 33.使用Spring集成Struts2 34.所有源码
使用 AOC 拦截器而不是过滤器进行 OpenSessionInView 处理 列出一个国家的城市和添加城市的可能性(bean 验证和自动检索 lat 和 lng 坐标) 安全 安全的 REST Web 服务 使用 CSRF 令牌 角度父状态的问题 有用的链接 ...
Spring的Ioc Spring的AOP , AspectJ Spring的事务管理 , 三大框架的整合 目录 1.1 Spring 框架学习路线:..........................................................................................................