2014-03-25 42 views
0

我想我的基於Spring MVC的應用程序使用Web服務。 我唯一知道的服務是WSDL。使用wsdl2java和Spring的Web服務客戶端

我使用this example from W3C進行測試。

我可以通過CXF的WSDL2Java實用程序生成客戶端的Java工件。它給了我一些接口和它們的實現以及main方法中的一些使用示例(但對此目的沒有多大幫助)。

我需要在我的應用程序中配置什麼配置才能簡單地集成此客戶端?我更喜歡XML conf aproach。

二手版本:

  • CXF 2.7.10
  • 春3.2.8

回答

3

CXF具有一個用於配置客戶端<jaxws:client />元素。

指定@WebService帶註釋的接口爲serviceClass屬性,並將端點URL指定爲address屬性。例如,假設WSDL2Java的生成com.w3schools.webservices.TempConvertSoap

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://cxf.apache.org/jaxws 
      http://cxf.apache.org/schemas/jaxws.xsd"> 

    <jaxws:client id="tempconvertClient" 
        serviceClass="com.w3schools.webservices.TempConvertSoap" 
        address="http://www.w3schools.com/webservices/tempconvert.asmx" /> 
</beans> 

,你可以注入tempconvertClient bean作爲com.w3schools.webservices.TempConvertSoap,並用它來使你的服務電話。

有關更多信息,請參閱CXF JAX-WS Configuration文檔。

+0

謝謝澄清,我會盡量嘗試。當然,我之前已經找到了這篇文章,但是我對這個問題的結果有點困惑,別管我的錯。 – Kousalik