【java后端开发问题合集】

大家如果有开发上问题可以私信我,我会发布解决文章在里面。

循环依赖

当出现这样的报错信息,说明我们的项目出现了循环依赖。

复制代码
***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the container form a cycle:

┌─────┐
|  serviceA defined in file [com/example/ServiceA.class]
↑     ↓
|  serviceB defined in file [com/example/ServiceB.class]
└─────┘

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.

实际举例

我们有class a , class b, class c.

复制代码
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;

@Component
public class ClassA {
    
    @Autowired  // 构造器注入
    private ClassB b;

}


@Component
public class ClassB {
    
    @Autowired  // 构造器注入
    private ClassC c;

}


@Component
public class ClassC {
    
    @Autowired  // 构造器注入
    private ClassC c;

}

这三类相互依赖,让我们的程序报错。解决方法如下。

彻底搞懂Java后端循环依赖:Spring解决原理+实战避坑指南(面试高频)-CSDN博客

前后端联调:跨域问题

相关推荐
福娃筱欢8 小时前
通用机KESV8R2-3节点集群缩容为2节点
java·开发语言
云泽8088 小时前
C++ 继承进阶:默认成员函数、多继承问题与继承组合选型
开发语言·c++
LXMXHJ8 小时前
项目之html+javaScript
java·vue
源代码•宸8 小时前
Golang原理剖析(defer、defer面试与分析)
开发语言·经验分享·后端·面试·golang·defer·开放编码
越甲八千8 小时前
FastAPI传参类型
开发语言·python·fastapi
毕设源码-赖学姐8 小时前
【开题答辩全过程】以 高校竞赛试题库管理平台为例,包含答辩的问题和答案
java
南山乐只8 小时前
Java并发原生工具:原子类 (Atomic Classes)
java·开发语言·后端
一颗青果8 小时前
C++下的atomic | atmoic_flag | 内存顺序
java·开发语言·c++
木叶子---9 小时前
pdf生成排查记录与解决方案
java·pdf
Sylvia-girl9 小时前
Java之异常
java·开发语言