Bean无法自动装配并返回NullPointerException

时间:2014-06-23 18:46:58

标签: java spring hibernate jpa

我正在使用Spring MVC和JPA / Hibernate框架开发ERP。 我的问题是服务层中的bean construireBilanImpl无法实例化,因为opmanimpl字段无法自动装配并返回NullPointerException

com.ensi.erp.metier.CreerBilanImpl:

@Transactional
@Component

public class ConstruireBilanImpl implements ConstruireBilan {

    @Autowired(required=true)
    private  OperationManager opmanimpl ;

    private float immobilisations_corporelles=sommeComptes(1266,1322);
public ConstruireBilanImpl(){};
    public void setOpmanimpl(OperationManagerImpl x){opmanimpl=x;}

    public float sommeComptes(int... doubles){
        if (this.opmanimpl==null){System.out.println("BAAAAAAAAAAAAAADDDDDDDDDD");}
        return opmanimpl.sommeComptes(doubles);


    }

com.ensi.dao.OperationMnagerImpl:

@Component
public class OperationManagerImpl implements OperationManager {

    @PersistenceContext(unitName="ERP")
        private EntityManager em;

        public OperationManagerImpl(){};

        public void setEm(EntityManager emm){em=emm;}


        public void creerOperation(opération op) {
            if (em!=null){System.out.print(" manager de bean initialisé");}

              em.persist(op);



            System.out.println("dou5oul---------2");}

        public opération rechercherOperation(int clé){
            opération oper=em.find(opération.class,clé);
            return oper;

        }

        public void supprimerOperation(int clé)
        {
            opération oper=em.find(opération.class,clé);
            em.remove(oper);
        }


        public void modifierId(int clé,int nv){
            opération oper=em.find(opération.class,clé);
            oper.setIdop(nv);
            em.flush(); 
        }
        public void modifierJournal(int clé,char j){
            opération oper=em.find(opération.class,clé);
            oper.setJournal(j);
            em.flush(); 

        }
        public void modifierCompte(int clé,int nvc){
            opération oper=em.find(opération.class,clé);
            oper.setCompte(nvc);
            em.flush(); 
        }
        public void modifierLibellé(int clé,String nvl ){
            opération oper=em.find(opération.class,clé);
            oper.setLibellé(nvl);
            em.flush(); 

        }
        public void modifierDate(int clé,Date nvd){

            opération oper=em.find(opération.class,clé);
            oper.setDateop(nvd);
            em.flush(); 
        }
        public void modifierDr(int clé,float nvdr){

            opération oper=em.find(opération.class,clé);
            oper.setDr(nvdr);
            em.flush(); 
        }
        public void modifierCr(int clé,float nvcr){

            opération oper=em.find(opération.class,clé);
            oper.setCr(nvcr);
            em.flush(); 
        }


        public List<opération> listeOpération() {
            String ss="select op from opération op";
            Query req= em.createQuery(ss);

            return req.getResultList();
        }


        public void SupprimerOpération(int ref){

            opération op=em.find(opération.class, ref);
            em.remove(op);

        }

        public float sommeComptes(int... doubles) {
            String liste= new String();
            String x;
            for (int d : doubles) {
                x=Integer.toString(d);
                x=x.concat(",");
                liste=liste.concat(x);
            }
        liste=liste.substring(0, liste.length()-1);
        String cc =" select sum(op.cr) from opération op ";
         System.out.println(cc);
            Query req= em.createQuery(cc);
            Number somme=(Number)req.getSingleResult();
            return somme.floatValue();

        }


    }

堆栈跟踪:

INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Jun 23 20:01:45 CEST 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5168781e: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,operationmanager,opser,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,operationController,operationManagerImpl,homeController,construireBilanImpl,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5168781e: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,operationmanager,opser,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,operationController,operationManagerImpl,homeController,construireBilanImpl,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'operationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:873)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:815)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 36 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:825)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 38 more
juin 23, 2014 8:01:47 PM org.apache.catalina.core.StandardContext listenerStart
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 'operationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'construireBilanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:873)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:815)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.dao.OperationManager com.ensi.erp.metier.ConstruireBilanImpl.opmanimpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 36 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ensi.erp.dao.OperationManager] is defined: expected single matching bean but found 2: [operationmanager, operationManagerImpl]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:825)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 38 more

3 个答案:

答案 0 :(得分:1)

接口OperationManager也可能有其他实现类。因此,Spring无法确定必须创建哪个实现。如果是这种情况,那么下面应该有所帮助。此外,界面不需要标记为Component

@Autowired(required=true) @Qualifier("operationManagerImpl") private OperationManager opmanimpl ;

答案 1 :(得分:0)

这是因为Spring没有opmanimpl找到bean,请使用

@Autowired(required=true)
@Qualifier("operationManagerImpl")
private  OperationManager opmanimpl ;

DOC

答案 2 :(得分:0)

堆栈跟踪清楚地表明您有多个bean有资格进行自动装配。您还没有显示您的配置,但我怀疑您正在使用组件扫描,然后还明确定义了一个bean。选一个。