admin管理员组

文章数量:1590135

一、序言

SpringBoot 2.6.x不推荐使用循环依赖,这是一个好消息,SpringBoot从底层逐渐引导开发者书写规范的代码,同时也是个忧伤的消息,循环依赖的应用场景实在是太广泛了。

如果从低版本升级到2.6.x,那么很大概率遇到的第一个问题便是循环依赖问题。

二、问题复原

1、代码说明

下面风格的代码比较普遍:两个类都有调用对方方法的需求,因此很容易写成循环引用。

@Service
public class TbDeptServiceImpl extends ServiceImpl<TbDeptMapper, TbDept> implements ITbDeptService {
    
    @Autowired
    private ITbStaffService staffService;
}
@Service
public class TbStaffServiceImpl extends ServiceImpl<TbStaffMapper, TbStaff> implements ITbStaffService {
    @Autowired
    private ITbDeptService deptService;
}

2、错误示例

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 autom

本文标签: 应对策略