org.springframework.beans.factory.BeanCurrentlyInCreationException
昨天下午的时候,给公司的项目打了个版,发现一直报502错误了,最后在服务器日志上看了一下异常信息,发现报了以下异常信息,导致项目启动就报错了(pc:该项目在我电脑本地启动不报错,之前也没报错)。
错误代码如下:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'voucherDynamicDao': Bean with name 'voucherDynamicDao' has been injected into other beans [voucherServiceImpl] 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.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:622) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:843) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
at cn.exrick.xboot.XbootApplication.main(XbootApplication.java:58) ~[classes!/:0.0.1]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[xcr.dev.jar:0.0.1]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[xcr.dev.jar:0.0.1]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[xcr.dev.jar:0.0.1]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[xcr.dev.jar:0.0.1]
异常分析:
BeanCurrentlyInCreationException是一个依赖闭环的问题,一般A依赖B,B依赖C,C依赖A容易导致这个问题,这样spring框架进行依赖注入创建bean的时候就容易发生异常。在本项目的代码中,则是因为VoucherDynamicDao注入了依赖voucherServiceImpl,而VoucherServiceImpl又注入了voucherDynamicDao。(PC:这是同事写的一段代码,很久很久都没动过,之前也没发生过异常,昨天突然出现了,因此告诫大家:编程需谨慎,务必符合规范)
解决方案:
原代码:
更正后的代码:
我们的编程习惯都是Service提供接口,ServiceImpl为Service接口的实现类,而@Service组件注解以及@Transactional事务注解都是加在ServiceImpl类上的,通常我们在Controller层或者其他层调用ServiceImpl里面的方法时,写的注入一般为service而不是serviceImpl,这样可以有效的防止出现依赖闭环问题,编程也更规范。
org.springframework.beans.factory.BeanCurrentlyInCreationException的更多相关文章
- 【异常】Application failed to start due to an exception org.springframework.beans.factory.BeanCurrentlyInCreationException
一. 异常信息: 2018-05-17 18:03:22.224 -DEBUG [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter ...
- 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;
一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...
- Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:
严重: Exception sending context initialized event to listener instance of class org.springframework.we ...
- org.springframework.beans.factory.annotation.Autowired(required=true)
Injection of autowired dependencies failed ERROR org.springframework.web.context.ContextLoader - Co ...
- 异常:Struts:org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find BasicDataSource
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.common ...
- org.springframework.beans.factory.BeanDefinitionStoreException
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'd ...
- org.springframework.beans.factory.BeanCreationException: 求教育!
2014-11-26 14:05:56 [org.springframework.web.context.support.XmlWebApplicationContext]-[WARN] Except ...
- org.springframework.beans.factory.BeanCreationException
org.springframework.beans.factory.BeanCreationException 这个是创建bean的异常. 我所遇到的情况是由下面这个引起的: @Resource an ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined
spring-session 集成redis,web.xml配置filter时候出现 No bean named 'springSessionRepositoryFilter' is defined ...
随机推荐
- python字符串的常见处理方法
python字符串的常见处理方法 方法 使用说明 方法 使用说明 string[start:end:step] 字符串的切片 string.replace 字符串的替换 string.split 字符 ...
- Python中print()函数不换行的方法以及分隔符替换
一.让print()函数不换行 在Python中,print()函数默认是换行的.但是,在很多情况下,我们需要不换行的输出(比如在算法竞赛中).那么,在Python中如何做到这一点呢? 其实很简单.只 ...
- 通过DatabaseMetaData数据库元信息类,获取特定数据库的元信息
数据库版本:mysql8.0.18 ide:idea 2019.3 可以看到代码中连接的数据库为course_select,是一个学生的选课系统的数据库 然后通过DatabaseMetaData的ge ...
- python - Lambda函数 匿名函数
Lambda 匿名函数 python 使用 lambda 来创建匿名函数. lambda只是一个表达式,函数体比def简单很多. lambda的主体是一个表达式,而不是一个代码块.仅仅能在lambda ...
- java工具类去掉字符串String中的.点。android开发java程序员常用工具类
下面是工具类详细代码: package com.qq986945193.david; /** * qq986945193 Project * ============================= ...
- unity 模板测试 详解
https://blog.csdn.net/u011047171/article/details/46928463#t4
- Unity3D如何有效地组织代码?
本文整理自知乎,原文链接:http://www.zhihu.com/question/21070379 问题: Unity3D可以说是高度的Component-Based Architecture,同 ...
- 最短路径(dijkstra 与 Floyd)
目录 1. 如何建图? 2. Floyd 3. Dijkstra 1. 如何建图? 要跑最短路,首先要有图 --鲁迅 常用的存储方法有两种,分别是邻接矩阵(用二维数组表示边)和邻接表(模拟链表表示边) ...
- tcpdump 命令格式
tcpdump 命令格式 tcpdump [选项] [表达式 1. 选项 常用选项: -i : 网卡名: 指定网卡,默认抓取系统第一个网卡 -n : 对地址以数字方式显示 -nn :对地址端口以数字方 ...
- 单线程模式从网易下载A股叁仟捌佰支股票一年的交易数据耗时十四分钟
代码下载:https://files.cnblogs.com/files/xiandedanteng/StockDataDownloader20200305.rar 压缩包内包含股票代号文件,调整好日 ...