springboot 循环依赖问题
springboot 循环依赖问题#
背景#
项目联合开发,也不知道谁制造的BUG
异常详情#
This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example
解决方案一:#
使用Bean标签注入的方式 添加lazy-init
属性
<bean id="ServiceDependent1" class="org.xyz.ServiceDependent1" lazy-init="true">
<constructor-arg ref="Service"/>
</bean>
<bean id="ServiceDependent2" class="org.xyz.ServiceDependent2" lazy-init="true">
<constructor-arg ref="Service"/>
</bean>
解决方案二:#
使用注解方式:
@Lazy
导包:
org.springframework.context.annotation.Lazy
总结#
两种方案的目的都是让其中一个Bean先加载完成【IOC初始化加载类 首先条件为:单例,非懒加载】,在加载另外一个懒加载类;【我们将另外一个类设置为懒加载,即可避免同时加载两个类,产生循环依赖问题】
分类:
springboot
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
2021-03-17 React[16x]框架
2021-03-17 Taro前端技术框架