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 ...
随机推荐
- All in One 你想知道的 hacker 技术都在这里
作者:HelloGitHub-小鱼干 hacker 这个词,大多数理解为黑客,而维基百科对其的定义为--黑客(Hacker)是指对设计.編程和计算机科学方面具高度理解的人,在本文中 hacker 主要 ...
- Shell编程—数据展示
1.标准文件描述符 Linux用文件描述符(file descriptor)来标识每个文件对象.文件描述符是一个非负整数,可以唯一标识会话中打开的文件.每个进程一次 多可以有九个文件描述符.出于特殊目 ...
- jdk 功能变化
JDK的变化 JDK1.5 JDK1.6 jdk1.7 1. 添加自动装箱,拆箱 1. =后可以省略泛型, 见ArrayList 2. try后加一个(), 定义流对象,作用域在try里 jdk1 ...
- Helix QAC/QAC++—代码静态测试工具介绍—符合功能安全标准MISRA ISO26262
Helix QAC是静态代码分析工具,依据C和C++编码规则自动扫描代码对规则的违背.开发团队在开发过程的早期就可以用它来检测缺陷,因为此时修改代码是最方便也最经济的.Helix QAC因此自动化强制 ...
- springboot文件上传(可单文件/可多文件)
获取文件内容,是从InputStream中获取,添加到指定位置的文件 如下所示 public static void getFile(InputStream is,File fileName) thr ...
- Struts+Servlet+JDBC网上手机销售系统
项目描述 Hi,大家好,今天给大家分享一个<网上手机销售系统>.本系统一共分为前台和后台两大模块,两个模块之间虽然在表面上是相互独立的,但是在对数据库的访问上是紧密相连的,各个模块访问的是 ...
- 微信小程序入门教程
首先请看demo 很简单的静态js就可以实现一款小程序开发. js.json.html.css四个核心文件 序言 开始开发应用号之前,先看看官方公布的「小程序」教程吧!(以下内容来自微信官方公布的「小 ...
- asterisk PBX 对接中国移动IMS
前提: 最近有项目需求,需要对接移动的IMS,移动的对接同事给出了信息: 用户名:+86750735xxxx@ims.gd.chinamobile.com 密码:123456 (系统导入的号码,默认 ...
- ZooKeeper的十二连问,你顶得了嘛?
前言 一线大厂ZooKeeper的十二连问,你顶得了嘛? 本文已经收录到github ❝ https://github.com/whx123/JavaHome ❞ 1. 面试官:工作中使用过Zooke ...
- Rakefile
Rakefile https://www.jianshu.com/p/b18a6e42455a RAKE – Ruby Make http://docs.seattlerb.org/rake/ bun ...