Jireh程序猿的那些事 Jireh程序猿的那些事

记录分享生活、程序、信息的精彩人生

目录
Spring循环引用报错 in its raw version as part of a circular reference, but has eventually been wrapped.
/      

Spring循环引用报错 in its raw version as part of a circular reference, but has eventually been wrapped.

Spring循环引用报错 in its raw version as part of a circular reference, but has eventually been wrapped.

解决方案:

取消@AllArgsConstructor注解

使用@Autowired注解,并且在@Autowired注解下再加上@Lazy注解

例如

@Service
public class DeviceServiceImpl implements IDeviceService {

	@Autowired
	@Lazy
	private IDeviceBaseService deviceBaseService;

}

@Lazy注解的功能是,在Spring 在启动的时候延迟加载这个bean,然后在他即调用这个bean的时候再去初始化,这样就避免了Spring循环引用的异常。

还有一种xml的方式这里就不写了,有兴趣的可以去查一下

但其实更好的解决办法是,对两个bean耦合的部份进行解耦,对公共部份抽离出来单独新建service。


如果觉得这篇文章不错的话,请我喝一杯 咖啡☕吧
标题:Spring循环引用报错 in its raw version as part of a circular reference, but has eventually been wrapped.
作者:Jireh
地址:https://jireh.xyz/articles/2020/04/10/1586502391529.html
本作品由 Jireh 采用 署名 – 非商业性使用 – 禁止演绎 4.0 国际许可协议进行许可,转载请注明出处。