【问题标题】:Spring: How to inject wsdlLocation in @WebServiceRefSpring:如何在@WebServiceRef 中注入 wsdlLocation
【发布时间】:2011-07-08 14:35:17
【问题描述】:

我正在使用 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);
    }
}

【问题讨论】:

    标签: java web-services jax-ws


    【解决方案1】:

    这在JAX-WS FAQ 中有半概述。您需要将端点字符串作为标准成员变量注入,然后使用...

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

    【讨论】:

    • 在这种情况下是行不通的。使用 @WebServiceRef 注释注入 Web 服务。我从不直接与 wsimport 生成的服务实现类进行交互。
    【解决方案2】:

    您可以使用LocalJaxWsPortProxyFactoryBean。您可以通过这个工厂 bean 配置 WSDL URL(除其他外)。这是来自official documentation的配置sn-p:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 2014-05-16
      • 2013-06-22
      • 2018-09-13
      • 2018-07-28
      • 2015-12-30
      • 1970-01-01
      相关资源
      最近更新 更多