解决springboot 循环依赖
错误提示
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.Despite circular references being allowed, the dependency cycle between beans could not be broken. Update your application to remove the dependency cycle.
- 问题是两个类互相调用,引发了循环依赖
解决方法:
- 简单方式
在注入的时候加上注解 @Lazy
@Lazy
EmployeeManagementService employeeManagementService;
如果注解不行:
- 暴力方式,在配置文件中,添加
spring:main:allow-circular-references: true
- 如果暴力方法没有解决,可以通过反射机制来解决:
EmployeeManagementService employeeManagementService;//解决循环依赖public EmployeeManagementService getEmployeeManagementService(){this.employeeManagementService=SpringUtil.getBean(EmployeeManagementService.class);return employeeManagementService;}
SpringUtil可以用hutool的
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.4.2</version></dependency>
也可以用xin.altitude.cms.common的SpringUtils
<dependency><groupId>xin.altitude.cms.common</groupId><artifactId>ucode-cms-common</artifactId><version>1.3.4</version></dependency>
如果找不到这个依赖可以添加
<repositories><repository><id>public</id><name>maven nexus</name><url>https://repo1.maven.org/maven2/</url><snapshots><updatePolicy>always</updatePolicy></snapshots></repository></repositories>
参考网址:https://www.jb51.net/article/238474.htm
解决springboot 循环依赖相关推荐
- SpringBoot循环依赖解决
一.循环依赖是什么? 我们了解到SpringBoot通过注解componentScan注解.将Bean注入到Spring容器.那么在注入过程中,如遇到这样的问题在将BeanA注入到容器中的过程中:Be ...
- Springboot 循环依赖
一.循环依赖 顾名思义多个类中的依赖形成了环路,形成了类似于死锁的情况,导致springboot在启动时无法为我们创建Bean.通俗来说 就是beanA中依赖了beanB,beanB中也依赖了bean ...
- Spring 通过 @Lazy 注解解决构造方法循环依赖问题
什么是循环依赖? 先定义两个类 Apple.Orange,如下所示: @Component public class Apple{@Autowiredprivate Orange orange; }@ ...
- Springboot循环依赖解决办法
最近在使用Spingboot做项目的时候,在引入shiro 后,启动项目一直报错 Error creating bean with name 'debtServiceImpl': Bean with ...
- 改了个字符串 项目无法启动,springboot循环依赖问题分析
一.描述 在一次项目开发中,业务方需要改下发送到kafka的json消息中key的名称,把字符串小写的"id"改成了大写的"Id" 在构建部署上线的过程中 线上 ...
- 什么是循环依赖?Spring如何解决循环依赖?
1. Spring创建代理原理 1.1 ProxyFactory类 第一步:创建一个基础SpringBoot项目 <!--web--> <dependency><grou ...
- 《Spring源码深度解析 郝佳 第2版》bean的加载、循环依赖的解决
往期博客: <Spring源码深度解析 郝佳 第2版>容器的基本实现与XML文件的加载 <Spring源码深度解析 郝佳 第2版>XML标签的解析 往期博客完成了xml文件加载 ...
- 图解Spring解决循环依赖
点击上方蓝色"方志朋",选择"设为星标"回复"666"获取独家整理的学习资料! 来源:juejin.cn/post/684490412216 ...
- Spring中-IOC-Bean的初始化-循环依赖的解决
前言 在实际工作中,经常由于设计不佳或者各种因素,导致类之间相互依赖.这些类可能单独使用时不会出问题,但是在使用Spring进行管理的时候可能就会抛出BeanCurrentlyInCreationEx ...
最新文章
- ping -c3 baidu.com ping过去是这样,代表网络畅通
- oracle 创建用户、授权、表空间
- UNIX(多线程):24---哪些STL容器是线程安全的
- Android中文乱码彻底解决
- maven工程的多环境配置方案(profile)
- 一个简单标注库的插件化开发实践
- java 计算2的64次幂_2的64次方
- 浙江省高校教师职称计算机考试成绩查询系统,浙江省高校招生考试信息管理系统...
- 通过计算机英语怎么说,通过英文怎么说
- Meson构建系统(一)
- php exif信息,显示照片exif信息PHP代码
- 电商后台设计详细讲解
- RIME输入法配置双拼方案(Ubuntu下基于ibus)
- 线性代数 --- 向量的内积与正交(垂直),Orthogonal Vectors
- 揭露数据不一致的利器 —— 实时核对系统
- matlab 层次聚类不均等巨雷,matlab层次聚类
- react 中子路由(route)或二级路由如何配置?
- 服务器ping显示不是内部,如何解决ping不是内部或外部命令问题_网站服务器运行维护,ping,内部,外部,命令...
- 尼康D90对焦模式图解
- Be All That You Can Be(做你自己)