我有两个类,每一个通过工厂自动生成同一个类:
@Service
public class AnalyseDispensationNominativeMetierService implements IAnalyseDispensationNominativeMetierService {
@Autowired
@Qualifier("interfaceAutomateServiceFactory")
private IInterfaceAutomateMetierService interfaceAutomateMetierService;
[...]
@Service
public class AnalysePreparationGlobaleMetierService implements IAnalysePreparationGlobaleMetierService {
@Autowired
@Qualifier("interfaceAutomateServiceFactory")
private IInterfaceAutomateMetierService interfaceAutomateMetierService;
[...]
@Service
public class InterfaceAutomate implements IInterfaceAutomateMetierService {
[...]
@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;
}
No unique bean of type [IInterfaceAutomateMetierService] is defined: expected single matching bean but found 2: [interfaceAutomate, interfaceAutomateServiceFactory]
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 with name 'analysePreparationGlobaleMetierService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dispensation.commun.service.metier.IInterfaceAutomateMetierService dispensation.analysePreparationGlobale.service.metier.impl.AnalysePreparationGlobaleMetierService.interfaceAutomateMetierService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [dispensation.commun.service.metier.IInterfaceAutomateMetierService] is defined: expected single matching bean but found 2: [interfaceAutomate, interfaceAutomateServiceFactory]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dispensation.commun.service.metier.IInterfaceAutomateMetierService dispensation.analysePreparationGlobale.service.metier.impl.AnalysePreparationGlobaleMetierService.interfaceAutomateMetierService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [dispensation.commun.service.metier.IInterfaceAutomateMetierService] is defined: expected single matching bean but found 2: [interfaceAutomate, interfaceAutomateServiceFactory]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:513)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)
at 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] is defined: expected single matching bean but found 2: [interfaceAutomate, interfaceAutomateServiceFactory]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:823)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:485)
... 22 more
最终,我通过更改factoryBean的名称来匹配注入字段的名称,并通过在项目扫描中删除一个条目来解决我的问题。(会不会是“双扫”惹的祸?)
<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;
我有这个超级班: 我想确定我完全理解了解决方案。通过,我给类DAOBase指定了特定的名称“daoBaseBeanname”,应用程序可以用它来标识类DAOBase,这样就不会把它与扩展DAOBase的其他类混淆了。对吗? 谢谢你。
我有这个超级班: 谢谢你。
由于Zuul不支持与SC的brixton.m3打包的版本中的补丁(https://github.com/spring-cloud/spring-cloud-netflix/issues/412),我正在尝试将一个基于Spring Boot+Spring Cloud的项目升级到brixton.m4。我启用了Spring-boot-starter-actul和spring-cloud-starter-
我有两个实体管理器配置用于两个单独的数据库,但当我尝试自动连接实体管理器来配置GraphQLExecutor bean时,我得到一个异常,指出有两个bean符合条件,尽管我在PersistenceContext中指定了一个单元名。 例外情况 注射 pom.xml
为什么我会犯这个错误。我该怎么解决呢? 谢谢