2011-07-08 34 views
1

我使用spring,並且在我的客戶端,一個web應用程序中,我需要與Jax-WS webservice進行交互。我現在通過使用@WebServiceRef註釋來註釋服務接口來工作。但是,我需要注入wsdlLocation屬性,因爲很明顯,Sun Microsystems或Oracle,生產中的Web服務wsdl位置將與開發期間使用的位置不同。Spring:如何在@WebServiceRef中注入wsdlLocation

如何注入wsdlLocation?

下面的代碼的極度簡化版本:

//This client service lives in the web app. wsimport used to generate artifacts. 
@Component 
public class MyClientServiceImpl implements MyClientService { 

    @WebServiceRef(wsdlLocation = "http://localhost:8080/ws/MyOtherService/the.wsdl", value = MyOtherServiceService.class) 
    //Interface generated by wsimport 
    private MyOtherService otherService; 

    @Override 
    public List<SomeSearchData> search(String searchString) { 
     return otherService.search(searchString); 
    } 
} 

回答

1

這在JAX-WS FAQ半概述。你需要注入端點字符串作爲一個標準的成員變量,然後使用...

((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.injectedEnpointURL); 
+0

這在這種情況下不起作用。 Web服務注入了@WebServiceRef註釋。我從不直接與wsimport生成的服務實現類交互。 –

0

您可以使用LocalJaxWsPortProxyFactoryBean。你可以通過這個工廠bean配置WSDL URL(等等)。下面是從official documentation配置片斷:

<bean id="accountWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> 
    <property name="serviceInterface" value="example.AccountService"/> 
    <property name="wsdlDocumentUrl" value="http://localhost:8888/AccountServiceEndpoint?WSDL"/> 
    <property name="namespaceUri" value="http://example/"/> 
    <property name="serviceName" value="AccountService"/> 
    <property name="portName" value="AccountServiceEndpointPort"/> 
</bean> 

然後你就可以讓Spring自動裝配這種依賴關係到你的目標bean(例如MyClientServiceImpl)。

相關問題