使用Spring+Xfire构建WebService


(1)编写发布接口ITrainTimeServiceRemote
(2)编写实现类TrainTimeServiceImpl
(3)编写发布配置文件application-webservice.xml
     <beans>
 <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 name="xfire" ref="xfire" />
 </bean>
        <bean id="traintimeService" parent="baseWebService">
  <property name="serviceBean" ref="traintimeService_implement" />
  <property name="serviceClass"
   value="com.bjjdsy.ky.zl.service.ITrainTimeServiceRemote" />
 </bean>
 <bean id="traintimeService_implement"
  class="com.bjjdsy.ky.zl.service.TrainTimeServiceImpl">
  <property name="traintimeDao">
   <ref bean="TrainTimeDAO" />
  </property>
 </bean>
(4)如果有方法返回复杂类型,则需要辨析配置文件,未知和接口文件放在同一包下
     ITrainTimeServiceRemote.aegis.xml
      <mappings>
       <mapping>
          <method name="getTrainTimeByTrainCode">
            <return-type componentType="com.bjjdsy.ky.zl.domain.ZlTrainTimeTab"/>
          </method>
       </mapping>
      </mappings>

 (5)web.xml配置
       <servlet>
          <servlet-name>XFireServlet</servlet-name>
          <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
          <load-on-startup>0</load-on-startup>
       </servlet>
       <servlet-mapping>
          <servlet-name>XFireServlet</servlet-name>
          <url-pattern>/services/*</url-pattern>
       </servlet-mapping>

调用:

<bean id="trainTimeService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
    <property name="serviceClass">
         <value>com.bjjdsy.ky.zl.service.ITrainTimeServiceRemote</alue>
    </property>
    <property name="wsdlDocumentUrl">           <value>http://10.100.2.12/KY_ZL_BASE/services/ITrainTimeServiceRemote?wsdl</value>
    </property>
</bean>

此后,就可以当作本地的trainTimeService来使用接口方法了  
   
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值