spring+struts+hibernate OpenSessionInView 配置学习
在web.xml中使用OpenSessionInView不能配置:
xml 代码
- <servlet>
- <servlet-name>contextservlet-name>
- <servlet-class>
- org.springframework.web.context.ContextLoaderServlet
- servlet-class>
- <load-on-startup>1load-on-startup>
- servlet>
需要配置 org.springframework.web.context.ContextLoaderListener:
xml 代码
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- listener-class>
- listener>
并且需要配置 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
xml 代码
- <filter>
- <filter-name>OpenSessionInViewfilter-name>
- <filter-class>
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
- filter-class>
- <init-param>
- <param-name>singleSessionparam-name>
- <param-value>trueparam-value>
- init-param>
- filter>
格外注意:
在配置struts-config.xml文件时,为了整合spring ,需要配置plugin:
xml 代码
- <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
- <set-property property="contextConfigLocation"
- value="/WEB-INF/classes/action- servlet.xml"/>
- plug-in>
但是,指定contextConfigLocation属性时, 只需要将配置strutsAction部分的spring配置文件引入,不能将配置数据源和事务管理的配置文件引入,否则OpenSessionInView将失效。