1.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>
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
2.spring.xml的配置如下
<!-- 引入xfire.xml-->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
<property name="serviceFactory" ref="xfire.serviceFactory"></property>
<property name="xfire" ref="xfire"></property>
</bean>
<!-- 要发布成WebService的接口实现类-->
<bean id="userSW" class="webservice.impl.UserServiceImpl"></bean>
<bean id="userService" parent="baseWebService">
<property name="serviceBean" ref="userSW"></property>
<property name="serviceClass" value="webservice.UserService"></property>
</bean>
3.客户端调用代码如下
Service serviceModel = new ObjectServiceFactory().create(UserService.class);
UserService service = (UserService) new XFireProxyFactory().create(serviceModel,"http://localhost:8080/xfire-service/service/UserService");
本文详细介绍了如何使用Spring和XFire框架整合实现WebService的开发过程,包括配置web.xml、spring.xml文件,以及客户端调用代码的示例。
908

被折叠的 条评论
为什么被折叠?



