项目报错This is often the result of over-eager type matching

  今天启动项目时报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'colorController': Unsatisfied dependency expressed through field 'jobService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'jobService': Bean with name 'jobService' has been injected into other beans [ProcessService,ProcessManualService] 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.

首先控制台是从一个controller报出的错

 跟踪发现

 于是去jobService中看看

 然后到这两个service中再看看,结果发现

构成了循环引用,去掉没有使用的引用,问题解决!

当然,如果你的系统过于庞大,不好找哪里构成了循环引用,可以使用spring提供的bean懒加载解决:

@Autowired
@Lazy
private ClassA classA;
@Autowired
@Lazy
private ClassB classB;

不过解决循环依赖,当然最好的方法是重构你的代码,进行解耦。

posted @   光何  阅读(12779)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2018-11-04 倾听内心,无谓西东

点击右上角即可分享
微信分享提示