简体   繁体   中英

Error with org.springframework.beans.factory.BeanCreationException

I want to call two SOAP web services and get data in my spring REST project.

I have two WSDL(VoucherService.wsdl and CGWebService.wsdl) files for different two(SOAP) web services.

First I add one WSDL(VoucherService.wsdl) to project and generate classes using "gradle wsdl2java" command.

Then updated ModuleConfig class with following Beans.

@Bean
public Jaxb2Marshaller getVoucherServiceMarshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath(environment.getProperty("voucher.service.marshaller.contextPath"));

rpr return marshaller; }

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

Then created VoucherServiceProxy class and add these autowired.

@Autowired
private WebServiceTemplate voucherServiceTemplate;

@Autowired
private Jaxb2Marshaller marshaller;

Then create required methods inside VoucherServiceProxy class and deployed, It works fine .

After that I generated classes for second WSDL(CGWebService.wsdl) using "gradle wsdl2java" command

Then created following Beans inside ModuleConfig class.

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

Then created ChargingGatewayServiceProxy and add these autowired.

@Autowired
private WebServiceTemplate cgServiceTemplate;

@Autowired
private Jaxb2Marshaller marshaller;

Inside VoucherServiceProxy class I created necessary methods.

Then I try to deploy it, but got this error .

Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.ws.client.core.WebServiceTemplate lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy.voucherServiceTemplate; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.ws.client.core.WebServiceTemplate] is defined: expected single matching bean but found 2: getVoucherServiceTemplate,getChargingGatewayServiceTempla te

Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DAppSyncServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy lk.ideahub.symphony.product.dapp.sync.service.DAppSyncServiceImpl.voucherServiceProxy; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'voucherServiceProxy': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.ws.client.core.WebServiceTemplate lk.ideahub.symphony.product.dapp.common.VoucherServiceProxy.voucherServiceTemplate; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.ws.client.core.WebServiceTemplate] is defined: expected single matching bean but found 2: getVoucherServiceTemplate,getChargingGatewayServiceTemplate

When I comment bean methods related for one service proxy in ModuleConfig class other service proxy is work without errors. But can't deploy with both.

Can someone help me to find a way to create these two service proxy class in same project without any bean factory error.

Add a @Qualifier to both WebServiceTemplate s, for creation and for usage, so Spring can distinguish between them and knows also which one to use.

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

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

injection, for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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