【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博客

前后端联调:跨域问题

相关推荐
程序员清风2 小时前
程序员兼职必看:靠谱软件外包平台挑选指南与避坑清单!
java·后端·面试
皮皮林5513 小时前
利用闲置 Mac 从零部署 OpenClaw 教程 !
java
华仔啊9 小时前
挖到了 1 个 Java 小特性:var,用完就回不去了
java·后端
SimonKing9 小时前
SpringBoot整合秘笈:让Mybatis用上Calcite,实现统一SQL查询
java·后端·程序员
日月云棠1 天前
各版本JDK对比:JDK 25 特性详解
java
用户8307196840821 天前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide1 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
IT探险家1 天前
Java 基本数据类型:8 种原始类型 + 数组 + 6 个新手必踩的坑
java
花花无缺1 天前
搞懂new 关键字(构造函数)和 .builder() 模式(建造者模式)创建对象
java
用户908324602731 天前
Spring Boot + MyBatis-Plus 多租户实战:从数据隔离到权限控制的完整方案
java·后端