问题:Spring循环依赖问题排查与解决

今天写代码遇到的问题

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.

2026-01-16 23:10:59.793 [main] ERROR o.s.b.diagnostics.LoggingFailureAnalysisReporter-

***************************

APPLICATION FAILED TO START

***************************

Description:

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

clazzController (field private com.itheima.service.ClazzService com.itheima.controller.ClazzController.clazzService)

┌─────┐

| clazzServiceImpl (field private com.itheima.service.StudentService com.itheima.service.impl.ClazzServiceImpl.studentService)

↑ ↓

| studentServiceImpl (field private com.itheima.service.ClazzService com.itheima.service.impl.StudentServiceImpl.clazzService)

└─────┘

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.

Disconnected from the target VM, address: '127.0.0.1:14901', transport: 'socket'

Process finished with exit code 1

最后一顿排查是因为循环依赖了,就是A依赖B,B又依赖A,导致项目起不起来

解决方法就是修改依赖,比如service调用mapper层来解决

相关推荐
打瞌睡的朱尤4 小时前
Vue day10 完整购物网页(登录页,首页,搜索)
前端·javascript·vue.js
RFG20124 小时前
20、详解Dubbo框架:消费方如何动态获取服务提供方地址?【微服务架构入门】
java·人工智能·后端·微服务·云原生·架构·dubbo
光泽雨4 小时前
C# 中 Assembly 类详解
开发语言·c#
少控科技4 小时前
C#基础训练营 - 02 - 运算器
开发语言·c#
扶苏10025 小时前
深入理解 Vue 3 的 watchEffect
前端·javascript·vue.js
Riemann~~5 小时前
C语言嵌入式风格
c语言·开发语言
zjttsh5 小时前
Linux下安装Redis
java
TimberWill6 小时前
SpringBoot整合Srping Security实现权限控制
java·spring boot·后端
Renhao-Wan7 小时前
Java 算法实践(四):链表核心题型
java·数据结构·算法·链表
zmzb01037 小时前
C++课后习题训练记录Day104
开发语言·c++