繁体   English   中英

org.springframework.beans.factory.BeanCreationException错误

[英]Error with org.springframework.beans.factory.BeanCreationException

我想在Spring REST项目中调用两个SOAP Web服务并获取数据。

我有两个用于不同的两个(SOAP)Web服务的WSDL(VoucherService.wsdl和CGWebService.wsdl)文件。

首先,我将一个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
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
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,getChargingGatewayServiceTempla te

上下文初始化失败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工厂错误的方法。

在两个WebServiceTemplate中都添加一个@Qualifier ,以进行创建和使用,因此Spring可以区分它们并知道要使用哪个。

@Bean
@Qualifier("voucher")
public WebServiceTemplate getVoucherServiceTemplate() {...}

@Bean
@Qualifier("chargingGateway")
public WebServiceTemplate getChargingGatewayServiceTemplate() {...}

注射,例如:

@Autowired
@Qualifier("chargingGateway")    
public WebServiceTemplate chargingGatewayServiceTemplate;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM