java - Spring FactoryBean and autowiring not working : expected single matching bean but found 2 -
i have 2 classes, each 1 autowiring same class through factory :
@service public class analysedispensationnominativemetierservice implements ianalysedispensationnominativemetierservice { @autowired @qualifier("interfaceautomateservicefactory") private iinterfaceautomatemetierservice interfaceautomatemetierservice; [...] @service public class analysepreparationglobalemetierservice implements ianalysepreparationglobalemetierservice { @autowired @qualifier("interfaceautomateservicefactory") private iinterfaceautomatemetierservice interfaceautomatemetierservice; [...]
the object want create through factory :
@service public class interfaceautomate implements iinterfaceautomatemetierservice { [...]
the factory :
@service("interfaceautomateservicefactory") public class interfaceautomateservicefactory implements factorybean<iinterfaceautomatemetierservice> { @autowired(required = true) private interfaceautomate ijininterfaceautomate; @override public iinterfaceautomatemetierservice getobject() { return ijininterfaceautomate; } @override public class<?> getobjecttype() { return iinterfaceautomatemetierservice.class; } @override public boolean issingleton() { return false; }
i keep getting following error, though i'm using qualifier annotation... idea on i'm doing wrong ? :
no unique bean of type [iinterfaceautomatemetierservice] defined: expected single matching bean found 2: [interfaceautomate, interfaceautomateservicefactory]
complete stack trace
grave: exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'analysepreparationglobalemetierservice': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private dispensation.commun.service.metier.iinterfaceautomatemetierservice dispensation.analysepreparationglobale.service.metier.impl.analysepreparationglobalemetierservice.interfaceautomatemetierservice; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no unique bean of type [dispensation.commun.service.metier.iinterfaceautomatemetierservice] defined: expected single matching bean found 2: [interfaceautomate, interfaceautomateservicefactory] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:287) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1106) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:925) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:472) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:388) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:293) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:111) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4723) @ org.apache.catalina.core.standardcontext$1.call(standardcontext.java:5226) @ org.apache.catalina.core.standardcontext$1.call(standardcontext.java:5221) @ java.util.concurrent.futuretask.run(futuretask.java:262) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.factory.beancreationexception: not autowire field: private dispensation.commun.service.metier.iinterfaceautomatemetierservice dispensation.analysepreparationglobale.service.metier.impl.analysepreparationglobalemetierservice.interfaceautomatemetierservice; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no unique bean of type [dispensation.commun.service.metier.iinterfaceautomatemetierservice] defined: expected single matching bean found 2: [interfaceautomate, interfaceautomateservicefactory] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:513) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:92) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:284) ... 20 more caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no unique bean of type [dispensation.commun.service.metier.iinterfaceautomatemetierservice] defined: expected single matching bean found 2: [interfaceautomate, interfaceautomateservicefactory] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:823) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:730) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:485) ... 22 more
in end, solved problem changing name of factorybean match name of injected field, , removing 1 entry in scanning of project. (could "double scanning" causing trouble ?)
<context:component-scan base-package="dispensation.**.factory.**,dispensation.**.metier.factory.**
=>
<context:component-scan base-package="dispensation.**.factory.**
@service("interfaceautomatemetierservice") public class interfaceautomateservicefactory implements factorybean<iinterfaceautomatemetierservice> {
@service public class analysepreparationglobalemetierservice implements ianalysepreparationglobalemetierservice { @autowired private iinterfaceautomatemetierservice interfaceautomatemetierservice;
Comments
Post a Comment