Spring: How to inject wsdlLocation in @WebServiceRef

青春壹個敷衍的年華 提交于 2020-01-01 19:38:10

问题


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

回答1:


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



回答2:


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).



来源:https://stackoverflow.com/questions/6626029/spring-how-to-inject-wsdllocation-in-webserviceref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!