ITeye博客

spring+struts+hibernate OpenSessionInView 配置学习

laukin · 2007-07-21 15:55 · 企业架构 · Spring · Struts · Hibernate · 配置管理 · Servlet · Markdown

spring+struts+hibernate OpenSessionInView 配置学习

在web.xml中使用OpenSessionInView不能配置:

xml 代码

  1. <servlet>
  2. <servlet-name>contextservlet-name>
  3. <servlet-class>
  4. org.springframework.web.context.ContextLoaderServlet
  5. servlet-class>
  6. <load-on-startup>1load-on-startup>
  7. servlet>

需要配置 org.springframework.web.context.ContextLoaderListener:

xml 代码

  1. <listener>
  2. <listener-class>
  3. org.springframework.web.context.ContextLoaderListener
  4. listener-class>
  5. listener>

并且需要配置 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter   

xml 代码

  1. <filter>
  2. <filter-name>OpenSessionInViewfilter-name>
  3. <filter-class>
  4. org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  5. filter-class>
  6. <init-param>
  7. <param-name>singleSessionparam-name>
  8. <param-value>trueparam-value>
  9. init-param>
  10. filter>

 格外注意:

在配置struts-config.xml文件时,为了整合spring ,需要配置plugin:

xml 代码

  1. <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
  2. <set-property property="contextConfigLocation"
  3. value="/WEB-INF/classes/action- servlet.xml"/>
  4. plug-in>

 

具体见:http://www.iteye.com/topic/15057

但是,指定contextConfigLocation属性时, 只需要将配置strutsAction部分的spring配置文件引入,不能将配置数据源和事务管理的配置文件引入,否则OpenSessionInView将失效。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。