关于spring+struts+ibatis+webService配置XML解决方法

    项目开发过程中应用到WEBSERVICE技术,在开发配置时走了一些弯路。应用xfire来取得项目中相关参数信息,拱其它项目应用。一般情况下, spring+ struts的组合,struts 作为web展现层,现在加xfire。
    其实,细心的朋友在做这个组合的时候,在配置的时候会出现一个问题。struts通过struts-config.xml文件中的 plugin与spring进行连接,而xfire通过在web.xml,配置一个listener和一个servlet与 spring 通信。struts会load一遍配置文件,listener也会load一遍配置文件。这样就会引起冲突。
    我在做配置的时候,就是出现了上面的问题。两次load配置文件的问题。我让struts里,加载dao,service,transaction 层的配置文件,web.xml加载xfire文件。然后,启动web工程,开始是正常的。struts+spring+ibatis的正常网页,一切正常。但是刚把service注入进xfire的时候,出现了无法加载的错误,也就是空指针。本来嘛,xfire和struts就是分着加载的。当时还想着是两次启动造成了spring的两个实例,两个实例之间不能共享。
    遇到的问题,在初次配置时系统会找不到相应WEBSERIVCE处理BEAN,原因是相关spring.xml(包括xfire-servlet.xml也是在此引用)引用是在struts-config.xml中引用,此时会无法正常找到webservice相应处理BEAN,原因是xfire-servlet.xml只能在web.xml中引用,在struts-config.xml会无正常引用。然后,尝试了N次,最后终于找到解决办法了。
    struts里,plugin这样写,value=""
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
		<set-property property="contextConfigLocation"
			value="" />
	</plug-in>

    web.xml中配置信息如下:注意最后引入的是xfire-servlet.xml,此时还要在配置文件中加入监听。
<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/spring.xml,/WEB-INF/springParas.xml,/WEB-INF/springSale.xml,/WEB-INF/springStore.xml,/WEB-INF/springTraffic.xml,/WEB-INF/springOtherFun.xml,/WEB-INF/springGroup.xml,/WEB-INF/springRfid.xml,/WEB-INF/xfire-servlet.xml</param-value> 

<listener>  
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener> 
    </context-param>


<servlet>     
     	<servlet-name>xfire</servlet-name>     
     	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  	</servlet>  
  	<servlet> 
     	<servlet-name>XFireServlet</servlet-name>  
     	<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>  
  	</servlet>  
  	<servlet-mapping>  
     	<servlet-name>XFireServlet</servlet-name>  
     	<url-pattern>/services/*</url-pattern>  
  	</servlet-mapping>   
  	<servlet-mapping>   
     	<servlet-name>xfire</servlet-name>  
     	<url-pattern>*.ws</url-pattern>  
  	</servlet-mapping>



     这样子,struts 和xfire就可以一起启动了。 因为xfire一定要通过web.xml启动。并且在webservice调试时可以正常找到bean,不会报错。

你可能感兴趣的:(spring,xml,struts,webservice,ibatis)