我是靠谱客的博主 纯真水池,这篇文章主要介绍启动报错org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean xxx,现在分享给大家,希望可以做个参考。

今天写代码,一顿操作,封装等待。启动发现报错了,翻车现场。。。
我的项目中代码

@Component
public class A {
	@Autowired
    private B b;
}

@Component
public class B {
	@Autowired
    private A a;
}

显然,出现了循环依赖。

解决方案

1. 设计层面解决

各业务层面的类做好分层,只有一个方向依赖关系,从根本上消灭循环依赖。
比如 Controller -> Service -> Dao
Service之间不做相互依赖

2. Spring懒加载

	@Lazy
	@Autowired
    private A a;

至此,问题解决。

最后

以上就是纯真水池最近收集整理的关于启动报错org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean xxx的全部内容,更多相关启动报错org.springframework.beans.factory.BeanCurrentlyInCreationException:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部