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");?