The dependencies of some of the beans in the application context form a cycle:实体间存在依赖循环bug解决方案,已解决

文章描述了一个SpringBoot应用因bean之间的依赖循环导致启动失败的问题。解决方案是更新应用程序以消除循环依赖,或者在配置文件中设置spring.main.allow-circular-references为true,允许循环引用以解决此问题。重启项目后,问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bug描述

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

Description:

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

   userController (field private com.cy.order.service.IUserService com.cy.order.controller.UserController.userService)
      ↓
   userServiceImpl (field protected com.baomidou.mybatisplus.core.mapper.BaseMapper com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.baseMapper)
      ↓
   userMapper defined in file [D:\IntelliJ IDEA 2018.3.4\IdeaProjects\order\target\classes\com\cy\order\mapper\UserMapper.class]
      ↓
   sqlSessionFactory defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]
┌─────┐
|  dataSource defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]
↑     ↓
|  org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.


Process finished with exit code 1

bug大致意思是不鼓励依赖循环引用,并且默认情况下禁止循环引用。更新应用程序以删除bean之间的依赖循环。作为最后的手段,可以通过将spring.min.allow-circular-references设置为true来自动打破循环。

bug解决办法

SpringBoot2.6正式发布:循环依赖默认禁止。如上提供解决方案为将spring.main.allow-circular-references 设置为 true,来自动中断循环。

如果是.properties文件,在文件中添加

spring.main.allow-circular-references=true

如果是.yml文件,在文件中添加

spring:
  main:
    allow-circular-references:true

重新启动项目,问题解决!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tllure

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值