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

前后端联调:跨域问题

相关推荐
云烟成雨TD20 小时前
Spring AI Alibaba 1.x 系列【6】ReactAgent 同步执行 & 流式执行
java·人工智能·spring
Wenweno0o20 小时前
0基础Go语言Eino框架智能体实战-chatModel
开发语言·后端·golang
于慨20 小时前
Lambda 表达式、方法引用(Method Reference)语法
java·前端·servlet
swg32132120 小时前
Spring Boot 3.X Oauth2 认证服务与资源服务
java·spring boot·后端
gelald20 小时前
SpringBoot - 自动配置原理
java·spring boot·后端
殷紫川20 小时前
深入理解 AQS:从架构到实现,解锁 Java 并发编程的核心密钥
java
一轮弯弯的明月20 小时前
贝尔数求集合划分方案总数
java·笔记·蓝桥杯·学习心得
chenjingming66620 小时前
jmeter线程组设置以及串行和并行设置
java·开发语言·jmeter
殷紫川20 小时前
深入拆解 Java volatile:从内存屏障到无锁编程的实战指南
java
eddieHoo20 小时前
查看 Tomcat 的堆内存参数
java·tomcat