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> 当我用地一种方案加入的时候,就错了。。有什么解决方案不

解决方案 »

  1.   

    <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> 正常都这么配置啊 <plug-in> 还一直没用过呢!
      

  2.   

    Struts两种集成Spring的方式,我想跟加载顺序有关
    在web.xml里通过配置Context-param来注册Spring的环境,这样在WebServer启动时就会加载
    而在struts-config.xml中注册Spring,可能得先加载Struts以后才加载Spring
    这样配置OpensessionInViewFilter可能会有错吧?
    不知楼主说出错是什么错啊?
      

  3.   

    不过真的还是建议在web.xml中注册Spring的环境,
    这样在WebServer一启动就会认识Spring的存在,
    然后用到它的一些组建的话可能也不容易出粗!
      

  4.   

    楼主所说的那两个配置是完全没有关系的!监听器只负责在你加载web.xml的时候注入相应的东西,而<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>只是Hibernate的一个延迟加载策略,至于在Struts的配置文件中用 <plug-in> 
    那只是通过插件的方式去注入相应的类,起到的作用和写监听器是一样的,今天有事忙就不在这里多写了,有意向了解更多信息的加我QQ260990509
      

  5.   

    如果我用<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?要不要*?
      

  6.   


    plug-in用的很少啊,为什么你不用最通用的做法呢?