问题: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层来解决

相关推荐
kyriewen33 分钟前
Skills 榜前 10 我全装了:只有 3 个能直接用
前端·javascript·程序员
海的透彻40 分钟前
dockerfile如何快速构建容器(java服务)
java·开发语言
IT_陈寒1 小时前
当Java的hashCode遇上Lombok,我的缓存被全清了
前端·人工智能·后端
code2cat1 小时前
Java工具篇之Gradle:用任务图组织构建与交付
java·开发语言·单元测试·gradle
北京中科新远科技1 小时前
高速交换机端口预算怎么做?下行、上联、拆分和冗余计算框架
开发语言·php
工控丫丫1 小时前
帆软看板中经常使用的公式函数及经常搭的组合
前端·javascript·数据库
xiaoye-duck1 小时前
《C++ 项目:手写大模型接入 SDK》DeepSeek接口设计(下):流式响应实现和测试
开发语言·网络·c++·语言模型
后台模板学习2 小时前
大模型 Prompt 工程在电商订单系统中的踩坑记录
java·python·prompt
w_zero_one2 小时前
算法--构造
java·数据结构·算法
jerrywus2 小时前
我用 GPT-6.1-sol 做了台会讲解的 3D 售货机:60 罐饮料,一口没喝上
前端·agent·claude