Spring: How to inject wsdlLocation in @WebServiceR

2019-04-15 06:15发布

I'm using spring and in my client, a web app, I need to interact with a Jax-WS webservice. I currently have it working via annotating the service interface with the @WebServiceRef annotation. However, I need the wsdlLocation property to be injected because, obviously Sun Microsystems or Oracle, the web service wsdl location in production will be different to what's being used during development.

How can I inject the wsdlLocation?

Here's an extremely simplified version of the code:

//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);
    }
}

2条回答
祖国的老花朵
2楼-- · 2019-04-15 06:41

You can use LocalJaxWsPortProxyFactoryBean. You can configure WSDL URL (among other things) via this factory bean. Here is a configuration snippet from the 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>

Then you can let Spring autowire this dependency into your target bean (e.g. MyClientServiceImpl).

查看更多
我想做一个坏孩纸
3楼-- · 2019-04-15 06:45

This is semi outlined in the JAX-WS FAQ. You need to inject the endpoint string as a standard member variable and then use...

((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.injectedEnpointURL); 
查看更多
登录 后发表回答