1.导入xfire-core包(有冲突包,具体哪些包见附件截图)
2.创建webservice接口
package byd.service;
import java.util.List;
import byd.entity.Commit;
public interface IBaseService {
public List<Commit> getList();
}
3.构建接口支持(为服务端提供对应数据类型,比如基本数据类型,list等,接口支持命名一般接口名称+aegis+.xml命名)
IBaseService.aegis.xml
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping>
<method name="getList">
<parameter componentType="java.lang.String" />
<return-type componentType="#commit" />
</method>
<component name="commit" class="byd.entity.Commit" componentType="byd.entity.Commit"/>
</mapping>
</mappings>
以上是返回list类型支持描述 其他普通类型可以去<component>节点
4.在WEB_INF下创建xfire-servlet.xml
与spring组合
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 引入XFire预配置信息 -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<!-- 定义访问的url-->
<bean class ="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/HelloWorldService.ws">
<ref bean="HelloWorldService"/>
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id ="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory"/>
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire"/>
</bean>
<bean id ="HelloWorldService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="webService"/>
<!-- 业务服务bean的窄接口类 -->
<property name ="serviceClass" value="byd.service.IBaseService"/>
</bean>
</beans>
6.在web.xml配置
<!-- begin XFire 配置 -->
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet >
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>*.ws</url-pattern>
</servlet-mapping>
<servlet>
<!-- 配合Spring容器中XFire一起工作的Servlet -->
<servlet-name>xfireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfireServlet</servlet-name>
<!-- 在这个URI下开放Web Service服务 -->
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- end XFire 配置 -->
xfire与spring组合创建webservice
于 2011-11-18 09:52:20 首次发布