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
Spring错误——Spring 注解——factory-bean reference points back to the same bean definition的更多相关文章
- Spring错误——Spring xml注释——org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 10; cvc-complex-type.2.3: 元素 'beans' 必须不含字符 [子级], 因为该类型的内容类型为“仅元素”。
背景:配置spring xml,注释xml中文件元素 错误: Caused by: org.xml.sax.SAXParseException; lineNumber: 24; columnNumbe ...
- Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
背景:学习切面,测试前置通知功能,xml配置如下 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- Spring错误——Spring 单元测试——Test class should have exactly one public constructor
背景:Spring 构建单元测试 错误 java.lang.Exception: Test class should have exactly one public constructor at or ...
- Spring 以及 Spring MVC Bean元素以及@Bean (Bean 等价于 注解 ??? 没理解错误吧)
①.由衷鸣谢Bossen <还是没看懂o(╥﹏╥)o><> {声明Spring Bean和注入Bean的几种常用注解和区别} Bean在Spring和SpringMVC中无所不 ...
- Spring课程 Spring入门篇 4-7 Spring bean装配之基于java的容器注解说明--@Scope 控制bean的单例和多例
1 解析 1.1 bean的单例和多例的应用场景 1.2 单例多例的验证方式 1.3 @Scope注解单例多例应用 2 代码演练 2.1 @Scope代码应用 1 解析 1.1 bean的单例和多例的 ...
- [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Spring 通过工厂方法(Factory Method)来配置bean
Spring 通过工厂方法(Factory Method)来配置bean 在Spring的世界中, 我们通常会利用bean config file 或者 annotation注解方式来配置bean. ...
- Spring IOC 源码简单分析 02 - Bean Reference
### 准备 ## 目标 了解 bean reference 装配的流程 ##测试代码 gordon.study.spring.ioc.IOC02_BeanReference.java ioc02 ...
- Spring课程 Spring入门篇 4-8 Spring bean装配之基于java的容器注解说明--基于泛型的自动装配
1 解析 1.1 什么是泛型? 1.2 泛型有什么作用? 1.3 泛型装配样式? 2 代码演练 2.1 泛型应用 1 解析 1.1 什么是泛型? Java泛型设计原则:只要在编译时期没有出现警告,那么 ...
随机推荐
- A - 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍 ...
- windows 安装mongodb
1.mongodb官网下载:http://www.mongodb.org/downloads 2.将下载的mongodb压缩包解压到对应文件夹,我的是:D:\pc\mongodb,请注意,我的bin目 ...
- 面向对象编程之Java多态
我相信从学习计算机面向对象编程起就很多人背下了继承.封装.多态三个特性,可是多态并不是那么好理解的.通常做几道题,背下几次多态的动态绑定规律,可是依旧在一段时间后忘记了多态的存在,为什么要多态,这个程 ...
- php三级联动(html,php两个页面)
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- 用友U8存货分类通过DataTable生成EasyUI Tree JSON
<%@ WebHandler Language="C#" Class="InventoryClass" %> using System; using ...
- ubuntu下设置mysql自启
- ECMAScript基础
概念: 1):区分大小写 2):变量是弱类型的. 3):每行结尾的分号可有可无 4):注释与Java,C和PHP语言的注释相同 5):括号表明代码块 原始值:是存储在栈中的简单数据段,也就是说他们的值 ...
- CentOS7.6 安装Docker
删除已安装的Docker # Uninstall installed docker sudo yum remove docker \ docker-client \ docker-client-lat ...
- eclipse maven项目下载jar包失败解决办法
1.找到我们的本地maven仓库目录 我的是 H:\Java\maven\Repository 2.搜索出该目录下的*lastUpdated.properties文件并删除,如下图所示,可以通过模糊搜 ...
- 多线程Thread
多线程的意义 使用多线程可以充分利用CPU资源.提高CPU的使用率,采用多线程的方式去同时完成几件事情而不互相干扰.在处理大量的IO操作或处理的情况需要花费大量的时间时(如:读写文件,视频图像的采集, ...