spring与XFire webservice集成的问题

web.xml配置文件内容

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<!-- 配置 contextConfigLocation参数  spring加载时从指定位置加载配置文件   context 参数使用-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
		classpath:applicationContext-*.xml
		</param-value>
	</context-param>
	
	<!-- log4j上下文 加载log4j配置文件 -->
	<context-param>
	<param-name>log4jConfigLocation</param-name>
	<param-value>classpath:log4j.xml</param-value>
	</context-param>
	
	
	<!-- spring 加载管理      Listener-->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- log4j加载日志 -->

	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>

	<!-- 在线人员统计     Listener -->
	<listener>
		<listener-class>com.yjm.count.PersonSessionListener</listener-class>
	</listener>
	<!-- 使用spring实现转码  Filter进行 转码使用   Filter-->
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- spring mvc 框架  配置入口  servlet 使用    Servlet -->
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- 配置 spring_mvc载入文件 -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-servlet.xml</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	<!--
		xFire 配置信息 Servlet org.codehaus.xfire.spring.XFireSpringServlet
		org.codehaus.xfire.transport.http.XFireConfigurableServlet
	-->

	<servlet>
		<servlet-name>XFireServlet</servlet-name>
		<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
		<!-- 初始化参数 默认调用config 已配置 spring -->
		<init-param>
			<param-name>config</param-name>
			<param-value>services.xml</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>XFireServlet</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>

	<!--欢迎页面 -->
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

spring 管理xfire_bean文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

   <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>

	<!-- webservice 实现方法 -->

	<bean id="webservicetest" class="com.yjm.service.WebServiceImp"></bean>
	<!-- 管理 xFire内置  配置对象 -->
	<bean id="testws" class="org.codehaus.xfire.spring.ServiceBean">
		<!-- 访问名字 -->
		<property name="name">
			<value>ws</value>
		</property>
		<!-- 命名空间 -->
		<property name="namespace">
			<value>http://ws.namespace.com</value>
		</property>
		<!-- 提供服务接口类 注入 -->
		<property name="serviceClass">
			<value>com.yjm.service.WebServiceInterface</value>
		</property>
		<!-- 注入服务实现类 -->
		<property name="serviceBean">
			<!-- 实际服务实现类 -->
			<ref bean="webservicetest" />
		</property>
	</bean>
</beans>


注意集成xfire xfire的 services.xml文件 就已经不用了

<?xml version="1.0" encoding="UTF-8"?>
	<!--
		<beans xmlns="http://xfire.codehaus.org/config/1.0"> <service
		xmlns="http://xfire.codehaus.org/config/1.0"></service> </beans>
	-->



web.xml里的xfire spring实现

org.codehaus.xfire.spring.XFireSpringServlet

已默认会从 

classpath:org/codehaus/xfire/spring/xfire.xml

里 去加载管理bean


主要是在配置里已经添加 这个 Bean的扩展了

 <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>

如果在 配置上下文为如下

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
		classpath:applicationContext-*.xml,
		classpath:org/codehaus/xfire/spring/xfire.xml
		</param-value>
	</context-param>

则会加载两遍xfire的管理 bean

=====================================================================

如果使用xfire的 这个servlet

org.codehaus.xfire.transport.http.XFireConfigurableServlet


则需要作如下修改:

web.xml

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
		classpath:applicationContext-*.xml,
		classpath:org/codehaus/xfire/spring/xfire.xml
		</param-value>
	</context-param>
services.xml
<?xml version="1.0" encoding="UTF-8"?>
	<!--
		<beans xmlns="http://xfire.codehaus.org/config/1.0"> <service
		xmlns="http://xfire.codehaus.org/config/1.0"></service> </beans>
	-->


你可能感兴趣的:(spring,webservice,xfire)