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

前后端联调:跨域问题

相关推荐
松☆1 小时前
C语言--结构体
c语言·开发语言
qq_348231851 小时前
Spring AI核心知识点
java·人工智能·spring
LitchiCheng1 小时前
Mujoco 蒙特卡洛采样统计机械臂可达工作空间(非Matlab)
开发语言·matlab
真正的醒悟1 小时前
图解网络8
开发语言·网络·php
徐_三岁1 小时前
Python 入门学习
java·python·学习
500841 小时前
鸿蒙 Flutter 接入鸿蒙系统能力:通知(本地 / 推送)与后台任务
java·flutter·华为·性能优化·架构
郝学胜-神的一滴1 小时前
Linux信号集操作函数详解
linux·服务器·开发语言·c++·程序人生
脸大是真的好~1 小时前
尚硅谷-Kafka02-主题创建-生产数据
java
落霞的思绪1 小时前
基于Go开发的矢量瓦片服务器——pg_tileserv
开发语言·后端·golang