• 背景:学习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 definitionat 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

转载于:https://www.cnblogs.com/zuiyue_jing/p/10431473.html

Spring错误——Spring 注解——factory-bean reference points back to the same bean definition相关推荐

  1. 小白踩坑记:spring初始化时出现:factory-bean reference points back to the same bean definition

    意思说的是你的factory-bean指向同一个bean定义,经过查看发现,我的类名和方法名一样(忽略大小写,因为当不指定名字时,默认是首字母小写作为bean的名字) // @Service publ ...

  2. 【死磕 Spring】—– IOC 之 Factory 实例化 bean

    这篇我们关注创建 bean 过程中的第一个步骤:实例化 bean,对应的方法为: createBeanInstance(),如下: protected BeanWrapper createBeanIn ...

  3. 【死磕 Spring】----- IOC 之 Factory 实例化 bean

    原文:https://www.cmsblogs.com/category/1391374860344758272 『chenssy』 这篇我们关注创建 bean 过程中的第一个步骤:实例化 bean, ...

  4. spring 扫描自定义注解

    目录 一:定义自定义注解 二:使用自定义注解 3.1 定义使用注解的测试文件路径 3.2继承BeanPostProcessor增加spring扫描配置 四:测试 目录结构: 一:定义自定义注解 pac ...

  5. Spring 通过工厂方法(Factory Method)来配置bean

    在spring的世界中, 我们通常会利用bean config file 或者 annotation注解方式来配置bean. 在第一种利用bean config file(spring xml)方式中 ...

  6. Spring的新注解——Configuration、ComponentScan、Bean、Import、PropertySource || spring整合Junit分析

    spring中的新注解 spring整合Junit分析 1.应用程序的入口       main方法 2.junit单元测试中,没有main方法也能执行     junit集成了一个main方法    ...

  7. Spring之使用注解实例化Bean并注入属性

    1.准备工作 (1)导入jar包 除了上篇文章使用到的基本jar包外,还得加入aop的jar包,所有jar包如下 所需jar包 (2)配置xml <?xml version="1.0& ...

  8. spring @Autowire 的注解默认是按类型注入bean

    spring @Autowire 的注解默认是按类型注入bean,比如下面这个类 import javax.sql.DataSource; import org.springframework.bea ...

  9. Spring高级之注解@Bean详解(超详细)

    定义/作用 当我们要使用第三方类实现组件注册到IOC容器时,例如第三方数据库连接池等,我们无法修改他们的代码,所以我们不能通过@Component及其衍生注解来进行组件定义.这是,可以通过@Bean注 ...

最新文章

  1. AGI:走向通用人工智能的【哲学】之现实世界的虚拟与真实——带你回看1998年的经典影片《The Truman Show》感悟“什么是真实”
  2. 非常抱歉,pmcaff网站硬盘故障,无法访问,努力恢复ing……
  3. php发送gmail,使用GMail SMTP服务器从PHP页面发送电子邮件
  4. EventSource
  5. 数据库兼容级别对数据备份还原的影响
  6. 汇编学习--7.13--标志寄存器
  7. android坐标画图软件下载,几何平板Geometry Pad(绘图,测量数字坐标轴)2.7.0
  8. spring封装VerifyCodeUtil工具类,生成图片验证码
  9. COIN3D拖拽器使用
  10. ryujinx模拟器linux安装教学,怪物猎人崛起 - ryujinx模拟器使用教程搬运,无机党的春天,MHR尝尝鲜 - 踩蘑菇社区...
  11. 感觉媒体、表示媒体、表现媒体、存储媒体和传输媒体
  12. Excel中VBA合并工作表
  13. ABAQUS软件实训(一):ABAQUS介绍
  14. android 键盘挡住popupwindow,软键盘遮挡住popupWindow问题
  15. C# WPF MVVM 实战 – 4 - 善用 IValueConverter
  16. 体系切换,华为IPD的研发管理之道(上)
  17. 非常不错的IOS学习网站
  18. 三星原生android手机,非原生系统??三星Android Go手机曝光
  19. 什么是obj文件?obj文件详解
  20. Discuz论坛升级攻略及踩坑处理

热门文章

  1. 复盘首届盘古石杯全国电子数据取证大赛晋级赛write up
  2. 【愚公系列】2022年11月 .NET CORE工具案例-.NET 7中的WebTransport通信
  3. 什么是四种七和弦 和三种转位
  4. 开发案例---微信定时推送:生日祝福
  5. 网页中加入当前时间html,如何在网页中加入当前时间的代码
  6. PyQt5实战:你是成熟的软件啦,该有启动画面和加载进度条了!
  7. java宠物小精灵_4978:宠物小精灵之收服
  8. centos使用xfreerdp登录报错
  9. 火车运煤问题(马车运草)问题
  10. 【间歇性努力,不是真正的努力】