当前位置: 代码迷 >> Web前端 >> spring+xfire公布webservice
  详细解决方案

spring+xfire公布webservice

热度:139   发布时间:2012-11-05 09:35:12.0
spring+xfire发布webservice

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");
?
  相关解决方案