【Spring循环依赖报错】The dependencies of some of the beans in the application context form a cycle

这篇具有很好参考价值的文章主要介绍了【Spring循环依赖报错】The dependencies of some of the beans in the application context form a cycle。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


一、报错信息


***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

   categoryController (field private com.vector.service.ICategoryService com.vector.controller.CategoryController.ICategoryService)
      ↓
   categoryService (field private com.vector.service.IArticleService com.vector.service.impl.CategoryServiceImpl.articleService)
┌─────┐
|  articleServiceImpl (field private com.vector.service.IUserService com.vector.service.impl.ArticleServiceImpl.iUserService)
↑     ↓
|  userServiceImpl (field private com.vector.service.IArticleService com.vector.service.impl.UserServiceImpl.iarticleService)
└─────┘




二、分析原因

       类A需要通过构造函数注入的类B的实例(或者B中声明的Bean),而类B需要通过构造函数注入的类A的实例(或者A中声明的Bean),导致循环依赖注入。


三、解决方案

解决方案一

其中一个不要引用对方,避免循环依赖,代码解耦肯定是最优解。

解决方案二

选择其中一个使用@Lazy 注解。

 @Autowired
 @Lazy
 private IArticleService articleService;

       延迟互相依赖的其中一个bean的加载,从而解决Spring在初始化bean的时候不知道先初始化哪个的问题。文章来源地址https://www.toymoban.com/news/detail-725261.html

到了这里,关于【Spring循环依赖报错】The dependencies of some of the beans in the application context form a cycle的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • IDEA报错:[ERROR] Some problems were encountered while processing the POMs

    报错信息:在处理Pom时发生了错误 无法解析父POM:xxx:x.x.x-RELEASE:找不到com.x.x:xxx:POM:x.x.x-RELEASEhttps://repo.maven.apache.org/maven2已缓存在本地存储库中,在经过中心的更新间隔或强制更新并且“parent.relativePath”指向错误的本地POM 点击File-Setting搜索Maven,点入以下页面,查看Maven的路

    2024年02月09日
    浏览(29)
  • 【Unity报错】Some objects were not cleaned up when closing the scene.

    Unity结束运行的时候报错Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?) 结束运行的时候突然报错,有概率,有时候有有时候没有 结束运行的时候在OnDestroy中调用了Mono的单例类,但是呢OnDestroy调用次序是不同的,有可能A先B后,也有可能是B先

    2024年02月02日
    浏览(31)
  • Ubuntu20.04安装软件报错:The following packages have unmet dependencies

    Ubuntu20.04更换阿里云源后安装软件都会报错:The following packages have unmet dependencies 查看资料,大概是ubuntu本身的源比较版本较老,而阿里云的源比较新,因此版本不匹配造成依赖的库不匹配,所以只要将阿里云的源换回Ubuntu官方源 1,替换源 : Ubuntu 的软件源配置文件是 /etc/

    2024年02月11日
    浏览(35)
  • Spring6-IoC(Inversion of Control)控制反转和DI(Dependency Injection)依赖注入,手动实现IOC

    Java 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法和属性;这种动态获取信息以及动态调用对象方法的功能称为 Java 语言的 反射机制 。简单来说, 反射机制指的是程序在运行时能够获取自身

    2024年02月09日
    浏览(54)
  • 【Flutter】运行报错:Cannot run with sound null safety, because the following dependencies

    flutter 在运行老项目的时候,或者是添加一些第三方库的时候,会报 Cannot run with sound null safety, because the following dependencies don‘t support null safety; 报错是因为这些包不支持safety模式。 解决方法: 运行的时候添加–no-sound-null-safety Android Studio工具 选择【Run】 --【 Edit Configuration

    2024年02月12日
    浏览(36)
  • 【报错解决】ERROR: pip‘s dependency resolver does not currently take into account all the packages

    使用pip安装 某些包时,报错: ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. spyder 5.1.5 requires pyqt55.13, which is not installed. spyder 5.1.5 requires pyqtwebengine5.13, which is not installed. conda-repo-cli 1.0.4

    2024年02月03日
    浏览(46)
  • 解决CitSpace分析新版本web of science文献报错“the timing slicing setting is outside the range of your data”

    新版web of science于2021年7月7日上线,旧版 Web of Science 将同步运行到2021年底。现在旧版web of science入口早已关闭,新本web of science的残产品中也不在提供旧页面入口。 近来在使用web of science文献制作CiteSpace图谱时发现,web of science导出的文献数据在CiteSpace跑的时候都会出现“th

    2024年02月02日
    浏览(34)
  • 报错:To see the full stack trace of the errors, re-run Maven with the -e switch.

    目录 报错信息: 报错场景: 报错原因:  解决方法: [ERROR] Java heap space - [Help 1] [ERROR]  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR]  [ERROR] For more information about the errors and possible solutions, please

    2024年02月07日
    浏览(40)
  • kafka-报错-The coordinator is not aware of this member

    我在项目里把原来用着的 独立消费者 consumer-group-id 同时当做消费者组来消费分区信息,导致协调器找不到这个 consumer-group-id 注册两个测试 topic 写一个消费者组 启动项目,发送消息 报错日志 查看kafka服务器的消费者状态

    2024年02月13日
    浏览(57)
  • Vivado报错[place 30-484] The packing of LUTRAM/SRL instance

            在Vivado Pr的时候报了一个错误:[Place 30-484] The packing of LUTRAM/SRL instance into capable slices could not be obeyde ....后面会继续说LUTRAM超了多少,而且会报错在你的ila上。           这个错误实际上是你的ila加了不被允许加的inout类型的信号,因为inout信号既是输入也是输出,一

    2024年02月13日
    浏览(55)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包