日期:2014-05-20  浏览次数:20682 次

OpenSessionInView
Struts结合Spring有两种方法
1.在Struts的配置文件中用<plug-in>
2.在web.xml中加入
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:applicationContext-*.xml</param-value>
  </context-param>
   
  <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

当我用第二种方案的时候,加入
  <filter>
  <filter-name>hibernateFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
 <filter-mapping>
  <filter-name>hibernateFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping> 

当我用地一种方案加入的时候,就错了。。有什么解决方案不

------解决方案--------------------
看不出来
------解决方案--------------------
Struts两种集成Spring的方式,我想跟加载顺序有关
在web.xml里通过配置Context-param来注册Spring的环境,这样在WebServer启动时就会加载
而在struts-config.xml中注册Spring,可能得先加载Struts以后才加载Spring
这样配置OpensessionInViewFilter可能会有错吧?
不知楼主说出错是什么错啊?
------解决方案--------------------
不过真的还是建议在web.xml中注册Spring的环境,
这样在WebServer一启动就会认识Spring的存在,
然后用到它的一些组建的话可能也不容易出粗!
------解决方案--------------------
楼主所说的那两个配置是完全没有关系的!监听器只负责在你加载web.xml的时候注入相应的东西,而<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>只是Hibernate的一个延迟加载策略,至于在Struts的配置文件中用 <plug-in> 
那只是通过插件的方式去注入相应的类,起到的作用和写监听器是一样的,今天有事忙就不在这里多写了,有意向了解更多信息的加我QQ260990509
------解决方案--------------------
探讨
如果我用 <plug-in>这种方案

  <context-param>
  <param-name>contextConfigLocation </param-name>
  <param-value>classpath*:applicationContext-*.xml </param-value>
  </context-param>
 
  <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
  </listener>就不需要了吧?

tomcat能正常启动

到页面上老是 no ContextLoaderListener registered错误

<plug-in>路径classpath*:applicationContext-*.xml?要不要*?

------解决方案--------------------
用通用的、、、