Bean with name ‘XX‘ has been injected into other beans [XX,XX] in its raw version.......... 错误分析及解决-程序员宅基地

技术标签: spring  奇怪Bug及不常见问题总结  

问题现象

启动出现大量异常,均以 Error create bean ‘xxx’ 开头,且很多类似如下

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxxservice': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxhandler': Injection of resource dependencies failed;nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'xxxxDao/Service': Bean with name 'xxxxDao/Service' has been injected into other beans [xxxxxService,xxxxxService,xxxxxService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
		at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
		at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1611)
		at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
		at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
		at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
		at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
		at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
		at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
		at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
		at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
		at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
		at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
		at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
		at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
		at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4763)
		at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5232)
		at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
		at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755)
		at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
		at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
		at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1775)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
		at java.lang.reflect.Method.invoke(Unknown Source)
		at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:291)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
		at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
		at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:483)
		at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
		at java.lang.reflect.Method.invoke(Unknown Source)
		at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:291)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
		at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
		at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(Unknown Source)
		at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
		at javax.management.remote.rmi.RMIConnectionImpl.access$300(Unknown Source)
		at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
		at java.security.AccessController.doPrivileged(Native Method)
		at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
		at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
		at java.lang.reflect.Method.invoke(Unknown Source)
		at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
		at sun.rmi.transport.Transport$1.run(Unknown Source)
		at sun.rmi.transport.Transport$1.run(Unknown Source)
		at java.security.AccessController.doPrivileged(Native Method)
		at sun.rmi.transport.Transport.serviceCall(Unknown Source)
		at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
		at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
		at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
		at java.security.AccessController.doPrivileged(Native Method)
		at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.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)
..................
..................

且每一行最后末尾都会指出被循环依赖的 bean 名

异常抛出由于是嵌套循环的,所以这一类错误的根本原因往往会置于每一行的最后以及日志的最后
且在日志的最后一处错误会具体写出如下错误,明显说明是循环依赖错误,是在错误日志的最后一部分!会出现类似如下错误:

Bean with name ‘xxxxService/dao’ has been injected into other beans [xxx,xxx,xxx] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using ‘getBeanNamesOfType’ with the ‘allowEagerInit’ flag turned off, for example…

circular reference 即循环依赖
在这里插入图片描述

解决方式

根据上面的截图可以知道 xxxxService/dao 在 has been injected into other beans [xxx,xxx,xxx] 即括号中的三个或多个类中被循环依赖,需要到 [xxx,xxx,xxx] 这几个类中去修改

方法一: 在被循环注入的类上再加注解 @Lazy (所在包 import org.springframework.context.annotation.Lazy;)

方法二:重构文件之间的依赖 解开循环依赖

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44131922/article/details/127296282

智能推荐

基于Java语言的安卓程序编程之二HelloWorld程序的运行_android中helloworld测试程序的执行过程-程序员宅基地

文章浏览阅读6.8k次,点赞3次,收藏11次。1 程序保存路径设置鼠标双击Eclipse.exe,打开Eclipse程序。首先在弹出的对话框中设置Eclipse的工作空间,即编写的安卓程序保存的路径,可以使用默认路径,也可以通过点击“Browse...”按键进行自定义设置,如图1-1所示。图1-1 设置Eclipse的工作空间2 安卓应用程序的创建2.1 新建程序在Eclipse主界面的菜单栏中,选择“File->_android中helloworld测试程序的执行过程

UVa 11287 - Pseudoprime Numbers_uva11287-程序员宅基地

文章浏览阅读168次。题目判断一个数是不是为伪素数。能够通过费马测试的合数。分析数论,直接按照定义判断即可。说明学python,ヾ(◍°∇°◍)ノ゙import mathdef is_prime(x): for i in range(2, int(math.sqrt(x))+2): if x % i == 0: return False ..._uva11287

大学python实训总结-【python实训总结和体会】作文写作问答 - 归教作文网-程序员宅基地

文章浏览阅读4.6k次。对python学习的总结怎么写1.Python初步Python是一种面向对象、直译式计算机程序设计语言。公认的特点是简单、易学、免费、开源等等。个人觉得特别喜欢Python的地方是对字符串操作特别的灵活、采取缩进的方式简单明了(虽然百度百科上把这个说成是局限)、以及简单的语法。Python 和c类似,是顺序进行的,不想visual c++是事件触发不同模块进行的。操作和matlab相似,有编辑窗口..._大学生python实训总结

解决Win下使用conda activate python虚拟环境无效的问题_conda activate environment不生效-程序员宅基地

文章浏览阅读8.9k次,点赞14次,收藏9次。在有些Win系统中会出现激活用户自定义的虚拟环境无效的问题conda activate env输入上述代码,并没有进入名为env的虚拟环境中。解决方法:首先输入命令行:activate可以看到进入了(base)环境中再输入:conda activate env即能成功进入名为env的虚拟环境..._conda activate environment不生效

怎么开启windows hypervisor platform,解决hypervisor platform消失无法安装的问题-程序员宅基地

文章浏览阅读3.7w次,点赞7次,收藏24次。正常的windows功能面板我的很好,没有安装windows hypervisor platform的机会,但是没关系然后cmd 或powershll 管理员身份运行Dism /online /Get-Features可以查看到hypervisor platform是禁用状态pushd “%~dp0”dir /b %SystemRoot%\servicing\Packages*..._windows hypervisor platform

MediaPlayer(二)--MediaPlayer基本框架_mediaplayerclassfactory-程序员宅基地

文章浏览阅读596次。MediaPlayer涉及的的文件路径这里参考的是android8.1 的代码JAVA类的路径:frameworks/base/media/java/android/media/MediaPlayer.javaJNI路径:frameworks/base/media/jni/android_media_MediaPlayer.cpp编译为 libmedia_jni.sonative 层的接口frameworks/av/media/libmedia编译为 libmedia.sonative层_mediaplayerclassfactory

随便推点

成本中心通过利润中心来和公司代码对应_sap 成本中心关联公司-程序员宅基地

文章浏览阅读7.4k次,点赞2次,收藏2次。成本中心是无法直接和公司代码进行配对的。但是利润中心能够绑定公司代码再通过利润中心的对应公司代码可以进行成本中心对应公司代码的对应_sap 成本中心关联公司

真实职场关于Web api学习指南(免费开放)一一5.Web api服务结构解析_c# .net5 web api 原理-程序员宅基地

文章浏览阅读1.6k次。真实职场关于Web api学习指南(免费开放)一一5.Web api服务结构解析_c# .net5 web api 原理

19. 二元连续型随机变量,联合概率密度_二元联合密度函数的分布函数-程序员宅基地

文章浏览阅读4.8k次,点赞5次,收藏15次。文章目录二元连续型随机变量,联合概率密度联合概率密度函数概率密度的性质二元连续型随机变量,联合概率密度联合概率密度函数定义:对于二元随机变量 (X,Y)(X, Y)(X,Y) 的 分布函数 F(x,y)F(x, y)F(x,y),如果存在非负函数 f(x,y)f(x,y)f(x,y),使对于任意 x,yx,yx,y,有F(x,y)=∫−∞x∫−∞yf(u,v) dudvF(x,y) ..._二元联合密度函数的分布函数

【PLC毕业设计】触摸屏立体车库控制系统毕业论文_200smart做毕业设计-程序员宅基地

文章浏览阅读2.2k次,点赞2次,收藏20次。【PLC毕业设计】触摸屏立体车库控制系统毕业论文_200smart做毕业设计

检测用户输入的单词是否是回文单词。所谓回文单词,是指单词逆序与原单词相同,例如:levelpop noon等_编写一个程序来检查是否可以重新排列给定的单词字母来形成回文单词。 回文是一个-程序员宅基地

文章浏览阅读390次。检测用户输入的单词是否是回文单词。所谓回文单词,是指单词逆序与原单词相同,例如:levelpop noon等_编写一个程序来检查是否可以重新排列给定的单词字母来形成回文单词。 回文是一个

《使用Java理解程序逻辑》内部测试机试题_使用面向对象思想,编写java程序。键盘接收用户输入的5位学生(student)的姓名(name-程序员宅基地

文章浏览阅读1.5k次。《使用Java理解程序逻辑》内部测试机试题 一、语言和环境 A、实现语言 Java B、环境要求 MyEclipse 10.7 二、功能要求 本次测试卷由下面4个机试题目组成。 1.编写Java程序,实现的..._使用面向对象思想,编写java程序。键盘接收用户输入的5位学生(student)的姓名(name

推荐文章

热门文章

相关标签