zoukankan      html  css  js  c++  java
  • Spring错误——Spring 注解——factory-bean reference points back to the same bean definition

    • 背景:学习Spring,在使用注解@Bean的name属性配置<bean>实例时,不能注册实例成功
    • 报错
      WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: 
               Invalid bean definition with name 'configure' defined in com.jing.spring.annotation.Configure: factory-bean reference points back to the same bean definition
      org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'configure' defined in com.jing.spring.annotation.Configure: factory-bean reference points back to the same bean definition
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:673)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:638)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:607)
          at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1486)
          at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1009)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
          at com.jing.spring.ioc.UnitTestBase.before(UnitTestBase.java:33)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    • 报错原因:Bean注解的value或者name值问题 在一个容器中存在的相同或者大小写相同的情况。类Configure装配到Bean容器中的默认id为configure,@Bean注解的name值与之存在冲突
      package com.jing.spring.annotation;
      
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      public class Configure {
      
          @Bean(name = {"configure","configure1"})
          public BeanConfigureI beanCon(){
              return new BeanConfigureImpl();
          }
      }
    • 解决方法:将注解@Bean的name属性值中的configura修改一下即可
      package com.jing.spring.annotation;
      
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      public class Configure {
      
          @Bean(name = {"configure2","configure1"})
          public BeanConfigureI beanCon(){
              return new BeanConfigureImpl();
          }
      }
    • Next
  • 相关阅读:
    N46期第一周作业
    备份MBR分区表,并破坏后修复
    预习作业(五)作业
    预习作业(四)作业
    通过v$sqlarea,v$sql查询最占用资源的查询
    ORACLE快速彻底Kill掉的会话
    HTML5中修改表单验证默认提示语句
    input正则 常用正则(备用)
    使用扫描枪扫描条码时字符识别写入缓慢问题(针对element-ui的el-input)优化
    JQuery经验汇总
  • 原文地址:https://www.cnblogs.com/zuiyue_jing/p/10431473.html
Copyright © 2011-2022 走看看