自动注入循环引用的问题

在Spring Boot项目中,Service A引用了Service B,同时Service B也引用了Service A,导致启动时出现UnsatisfiedDependencyException异常。异常信息涉及到Bean的循环创建问题。分析原因是由于相互引用造成的初始化死循环。解决方法是在其中一个Service上使用@Lazy注解实现延迟加载,从而打破循环引用的困境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目场景:

springboot项目中不同的service注入的时候进行了相互引用。

问题描述:

service A引用了servie B 而Service B 又引用了 Service A,于是项目在启动的时候就出现了循环引用注入的问题。

项目启动出现的异常信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘subscriber’: Unsatisfied dependency expressed through field ‘schemeService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘verificationSchemeServiceImpl’: Unsatisfied dependency expressed through field ‘verificationRuleService’; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘verificationRuleService’: Bean with name ‘v

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值