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
本文标签: 应对策略
版权声明:本文标题:SpringBoot2.6.x默认禁用循环依赖后的应对策略 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728084109a1144779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论