springboot项目报错问题总结

ops/2024/11/29 17:01:46/

springboot循环依赖问题处理

  • 发现问题

    java">
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2024-11-27 21:30:58.695 [f8cd6df4693e404aa607363bbe3dcf00] [main] ERROR o.s.boot.SpringApplication -  - Application run failed
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'contextBaseRegistryConfiguration': Unsatisfied dependency expressed through field 'groupQrTaskDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupQrTaskDetailsServiceImpl': Unsatisfied dependency expressed through method 'setSyyyAccountService' parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'syyyAccountServiceImpl': Bean with name 'syyyAccountServiceImpl' has been injected into other beans [standardTaskServiceImpl] 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.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)at com.jd.bpo.jingxiaoge.api.JingxiaogeApiApp.main(JingxiaogeApiApp.java:39)
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupQrTaskDetailsServiceImpl': Unsatisfied dependency expressed through method 'setSyyyAccountService' parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'syyyAccountServiceImpl': Bean with name 'syyyAccountServiceImpl' has been injected into other beans [standardTaskServiceImpl] 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.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:768)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:720)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657)... 20 common frames omitted
    Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'syyyAccountServiceImpl': Bean with name 'syyyAccountServiceImpl' has been injected into other beans [standardTaskServiceImpl] 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.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:631)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:760)... 34 common frames omitted
  • 分析问题
    从最后一行看问题:

    Error creating bean with name ‘syyyAccountServiceImpl’: Bean with name ‘syyyAccountServiceImpl’ has been injected into other beans [standardTaskServiceImpl] in its raw version as part of a circular reference

    说明在standardTaskServiceImpl bean中注入的syyyAccountServiceImpl,导致循环依赖了。如下:
    在这里插入图片描述

  • 解决问题
    可能的解决方案:

    • 重构代码以消除循环依赖:

      将某些依赖改为方法注入: 如果可能,使用方法注入而不是构造函数注入,这样可以延迟依赖的解决,直到bean实际需要它为止。
      引入一个中间层: 通过引入一个新的服务或者将某些功能拆分到不同的类中,以消除循环依赖。

    • 使用@Lazy注解:

      在一个或多个依赖的bean上加上@Lazy注解,这会告诉Spring在需要时再初始化这个bean,而不是在启动时立即初始化。例如:
      在这里插入图片描述

    • 考虑使用ApplicationContext手动获取Bean:

      在需要的地方,通过ApplicationContext获取bean,这样避免了自动注入带来的循环依赖问题。


http://www.ppmy.cn/ops/137690.html

相关文章

结构型模式-装饰器模式

装饰者模式(Decorator Pattern)是一种结构型设计模式,主要用于动态地给对象添加一些额外的职责,而无需修改其代码。通过将对象放入包含行为的装饰器对象中,能够有效地扩展功能,同时保持原始类的结构和代码完…

从单机缓存到分布式缓存那些事

作者:秦怀 1 缓存前世今生 1.1 故事从硬件开始 Cache 一词来源于 1967 年的一篇电子工程期刊论文。其作者将法语词“cache”赋予“safekeeping storage”的涵义,用于电脑工程领域。当时没有 Cache,CPU 和内存都很慢,CPU 直接访…

【超详细】卷积神经网络CNN基本架构以及工作原理详解

《------往期经典推荐------》 一、AI应用软件开发实战专栏【链接】 项目名称项目名称1.【人脸识别与管理系统开发】2.【车牌识别与自动收费管理系统开发】3.【手势识别系统开发】4.【人脸面部活体检测系统开发】5.【图片风格快速迁移软件开发】6.【人脸表表情识别系统】7.【…

限制账号密码格式的正则表达式来啦

. 代表任意字符 \w 代表字母、数字、下划线 \d 代表数字 指定字符重复1次或者n次,最少1次 ? 指定字符重复0-1次 {n} 只能重复n次 {a,} 最少重复a次 {,a} 最多重复a次 {a,b} 最少重复a次,最多重复b次 \s 空格 | 代表或者 [a-zA-Z0-9]&#xf…

Fanuc法那科机器人维修之参考位置详解

参考位置是预先设定好的一个或多个特定点位,当启用这一功能时,系统会实时且精确地判断机器人的当前关节角度是否处于预设参考位置的一定范围之内(这个范围区间是可以根据实际需求进行设置的),并据此输出指定的信号。 这…

【设计模式】【结构型模式(Structural Patterns)】之外观模式(Facade Pattern)

1. 设计模式原理说明 外观模式(Facade Pattern) 是一种结构型设计模式,它提供了一个统一的接口,用来访问子系统中的一群接口。外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。通过隐藏子系统的复杂…

【FPGA】UART串口通信

文章目录 一、通信方式1.串行通信2.并行通信 二、UART串口通信1.模块设计与时序图2.代码实现 三、测试结果1.仿真结果2.上板验证 一、通信方式 1.串行通信 串行通信是指利用一条传输线将数据一位位地顺序传送。(也就是说串行通信传输的数据是1比特1比特的传送的&a…

【closerAI ComfyUI】物体转移术之AI模特换装,Flux三重控制万物一致性生图,赋能电商产品行业,小白两步完成!

更多AI前沿科技资讯,请关注我们: closerAIGC closerAI,一个深入探索前沿人工智能与AIGC领域的资讯平台,我们旨在让AIGC渗入我们的工作与生活中,让我们一起探索AIGC的无限可能性!closerAI-一个深入探索前沿人工智能与AIGC领域的资讯平台 产品经理逛世界 一只在互联网PM浪…