我正在使用spring,在我的客户端,一个Web应用程序,我需要与Jax-WS Web服务进行交互。我目前通过使用@WebServiceRef注释来注释服务接口来实现它。但是,我需要注入wsdlLocation属性,因为显然,Sun Microsystems或Oracle,生产中的Web服务wsdl位置将与开发期间使用的位置不同。
如何注入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);
}
}
答案 0 :(得分:1)
这是JAX-WS FAQ中的半概述。您需要将端点字符串作为标准成员变量注入,然后使用...
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.injectedEnpointURL);
答案 1 :(得分: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
)。