想解决问题: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>
-->
分享到:
相关推荐
- **二级缓存**:提高数据访问效率,OpenSessionInView模式下配合Spring实现 session级缓存。 **OpenSessionInView模式** OpenSessionInView模式是一种解决数据持久层和Web层之间事务管理的策略。在用户请求到达时...
**OpenSessionInView模式**是一种常用的Hibernate优化模式,其主要目的是解决Hibernate的一级缓存问题。通过这种方式,可以确保在一个HTTP请求的生命周期内,Hibernate的Session始终处于打开状态,从而避免了因...
在使用Spring框架时,推荐采用OpenSessionInView模式,确保请求处理的整个过程中数据库会话保持打开。这样可以避免因事务过早关闭导致的懒加载问题,但需要注意不要在视图层进行大数据量的分页查询,以免内存溢出。 ...
Hibernate的缓存策略与openSessionInView模式** 缓存策略是Hibernate性能优化的关键,而`openSessionInView`模式则是在Web应用中实现一级缓存的有效手段。它通过在每个请求开始时打开一个`Session`,并在请求结束...
希望本篇文章能帮助初学者快速入门Spring配置,进而在实际项目中灵活运用Spring框架的强大功能。 以上是对Spring配置的总结,包括了web.xml中的关键配置点,以及Struts与Spring的集成方式。通过对这些内容的学习和...
6. **Struts框架**:理解多层架构,Model1和Model2模式,Struts的基本概念,MVC模式,Action与业务逻辑类的关系,数据传递,Struts处理流程,Struts标签库,ActionForm,文件上传,类型转换,DTO,动态ActionForm,...