问题描述:

┌─────┐
|  xbdUserServiceImpl (field com.xbd.service.user.IXbdUserPermissionService com.xbd.serviceimpl.user.XbdUserServiceImpl.userPermissionService)
↑     ↓
|  xbdUserPermissionServiceImpl (field com.xbd.service.user.IXbdUserService com.xbd.serviceimpl.user.XbdUserPermissionServiceImpl.userService)
└─────┘

如上所述:xbdUserServiceImpl 注入了 userPermissionService
xbdUserPermissionServiceImpl 注入了 userService 导致的循环引用

之前spring-boot 版本中迁移过来的,老版本是 2.3.4.RELEASE
现在版本是 org.springframework.boot:spring-boot-starter:2.7.18 的版本

解决方案

1: 修改代码

修改现有两个类中的依赖关系,防止循环依赖的情况出现

2:打开循环引用

循环依赖被禁用了,打开就可以了,版本是springboot2.6.x 之后的版本,之前的版本默认是开启的

spring:
    main:
        allow-circular-references: true  #允许循环引用

使用懒加载

注解@Lazy注解(懒加载)和@Autowired注解同时使用解决

形如:
 @Lazy
 @Autowire
 IXbdUserService userService;
GitHub 加速计划 / de / Dependencies
42
2
下载
A rewrite of the old legacy software "depends.exe" in C# for Windows devs to troubleshoot dll load dependencies issues.
最近提交(Master分支:4 个月前 )
1997a400 - 4 年前
2f423539 - 4 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐