【发布时间】:2016-03-03 17:21:24
【问题描述】:
我想调用两个 SOAP Web 服务并在我的 spring REST 项目中获取数据。
我有两个 WSDL(VoucherService.wsdl 和 CGWebService.wsdl)文件用于不同的两个(SOAP)Web 服务。
首先我添加一个 WSDL(VoucherService.wsdl) 到项目并使用“gradle wsdl2java”命令生成类。
然后使用以下 Bean 更新 ModuleConfig 类。
@Bean
public Jaxb2Marshaller getVoucherServiceMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(environment.getProperty("voucher.service.marshaller.contextPath"));
rpr 返回编组器; }
@Bean
public WebServiceTemplate getVoucherServiceTemplate() {
WebServiceTemplate template = new WebServiceTemplate(getVoucherServiceMarshaller());
template.setDefaultUri(environment.getProperty("voucher.service.defaultUri"));
return template;
}
@Bean
public VoucherServiceProxy getVoucherServiceProxy() {
VoucherServiceProxy voucherServiceProxy = new VoucherServiceProxy();
return voucherServiceProxy;
}
然后创建 VoucherServiceProxy 类并添加这些 autowired。
@Autowired
private WebServiceTemplate voucherServiceTemplate;
@Autowired
private Jaxb2Marshaller marshaller;
然后在 VoucherServiceProxy 类中创建所需的方法并部署,它工作正常。
之后,我使用“gradle wsdl2java”命令为第二个 WSDL(CGWebService.wsdl) 生成了类
然后在 ModuleConfig 类中创建以下 Bean。
@Bean
public ChargingGatewayServiceProxy getChargingGatewayServiceProxy() {
ChargingGatewayServiceProxy chargingGatewayServiceProxy = new ChargingGatewayServiceProxy();
return chargingGatewayServiceProxy;
}
@Bean
public Jaxb2Marshaller getChargingGatewayServiceMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(environment.getProperty("cg.service.marshaller.contextPath1"));
return marshaller;
}
@Bean
public WebServiceTemplate getChargingGatewayServiceTemplate() {
WebServiceTemplate template = new WebServiceTemplate(getChargingGatewayServiceMarshaller());
template.setDefaultUri(environment.getProperty("cg.service.url"));
return template;
}
然后创建 ChargingGatewayServiceProxy 并添加这些 autowired。
@Autowired
private WebServiceTemplate cgServiceTemplate;
@Autowired
private Jaxb2Marshaller marshaller;
在 VoucherServiceProxy 类中我创建了必要的方法。
然后我尝试部署它,但收到此错误。
自动装配依赖注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 org.springframework.ws.client.core.WebServiceTemplate lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy.voucherServiceTemplate;嵌套异常是 org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义类型 [org.springframework.ws.client.core.WebServiceTemplate] 的合格 bean:预期的单个匹配 bean 但找到了 2:getVoucherServiceTemplate,getChargingGatewayServiceTemplate
上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名为“DAppSyncServiceImpl”的bean时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy lk.ideahub.symphony.product.dapp.sync.service.DAppSyncServiceImpl.voucherServiceProxy;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“voucherServiceProxy”的 bean 时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 org.springframework.ws.client.core.WebServiceTemplate lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy.voucherServiceTemplate;嵌套异常是 org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义 [org.springframework.ws.client.core.WebServiceTemplate] 类型的限定 bean:预期的单个匹配 bean 但找到了 2:getVoucherServiceTemplate,getChargingGatewayServiceTemplate
当我在 ModuleConfig 类中评论与一个服务代理相关的 bean 方法时,其他服务代理可以正常工作。但不能同时部署。
谁能帮我找到一种方法在同一个项目中创建这两个服务代理类而不会出现任何 bean 工厂错误。
【问题讨论】:
标签: java spring web-services spring-mvc wsdl