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 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相关推荐
- 小白踩坑记:spring初始化时出现:factory-bean reference points back to the same bean definition
意思说的是你的factory-bean指向同一个bean定义,经过查看发现,我的类名和方法名一样(忽略大小写,因为当不指定名字时,默认是首字母小写作为bean的名字) // @Service publ ...
- 【死磕 Spring】—– IOC 之 Factory 实例化 bean
这篇我们关注创建 bean 过程中的第一个步骤:实例化 bean,对应的方法为: createBeanInstance(),如下: protected BeanWrapper createBeanIn ...
- 【死磕 Spring】----- IOC 之 Factory 实例化 bean
原文:https://www.cmsblogs.com/category/1391374860344758272 『chenssy』 这篇我们关注创建 bean 过程中的第一个步骤:实例化 bean, ...
- spring 扫描自定义注解
目录 一:定义自定义注解 二:使用自定义注解 3.1 定义使用注解的测试文件路径 3.2继承BeanPostProcessor增加spring扫描配置 四:测试 目录结构: 一:定义自定义注解 pac ...
- Spring 通过工厂方法(Factory Method)来配置bean
在spring的世界中, 我们通常会利用bean config file 或者 annotation注解方式来配置bean. 在第一种利用bean config file(spring xml)方式中 ...
- Spring的新注解——Configuration、ComponentScan、Bean、Import、PropertySource || spring整合Junit分析
spring中的新注解 spring整合Junit分析 1.应用程序的入口 main方法 2.junit单元测试中,没有main方法也能执行 junit集成了一个main方法 ...
- Spring之使用注解实例化Bean并注入属性
1.准备工作 (1)导入jar包 除了上篇文章使用到的基本jar包外,还得加入aop的jar包,所有jar包如下 所需jar包 (2)配置xml <?xml version="1.0& ...
- spring @Autowire 的注解默认是按类型注入bean
spring @Autowire 的注解默认是按类型注入bean,比如下面这个类 import javax.sql.DataSource; import org.springframework.bea ...
- Spring高级之注解@Bean详解(超详细)
定义/作用 当我们要使用第三方类实现组件注册到IOC容器时,例如第三方数据库连接池等,我们无法修改他们的代码,所以我们不能通过@Component及其衍生注解来进行组件定义.这是,可以通过@Bean注 ...
最新文章
- AGI:走向通用人工智能的【哲学】之现实世界的虚拟与真实——带你回看1998年的经典影片《The Truman Show》感悟“什么是真实”
- 非常抱歉,pmcaff网站硬盘故障,无法访问,努力恢复ing……
- php发送gmail,使用GMail SMTP服务器从PHP页面发送电子邮件
- EventSource
- 数据库兼容级别对数据备份还原的影响
- 汇编学习--7.13--标志寄存器
- android坐标画图软件下载,几何平板Geometry Pad(绘图,测量数字坐标轴)2.7.0
- spring封装VerifyCodeUtil工具类,生成图片验证码
- COIN3D拖拽器使用
- ryujinx模拟器linux安装教学,怪物猎人崛起 - ryujinx模拟器使用教程搬运,无机党的春天,MHR尝尝鲜 - 踩蘑菇社区...
- 感觉媒体、表示媒体、表现媒体、存储媒体和传输媒体
- Excel中VBA合并工作表
- ABAQUS软件实训(一):ABAQUS介绍
- android 键盘挡住popupwindow,软键盘遮挡住popupWindow问题
- C# WPF MVVM 实战 – 4 - 善用 IValueConverter
- 体系切换,华为IPD的研发管理之道(上)
- 非常不错的IOS学习网站
- 三星原生android手机,非原生系统??三星Android Go手机曝光
- 什么是obj文件?obj文件详解
- Discuz论坛升级攻略及踩坑处理