spring service层 循环引用问题。

spring service层 循环引用问题。 

报错信息如下:
Error creating bean with name 'smsCodeApiController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zhenler.microcode.service.IWechatUserService com.zhenler.commonality.controller.api.SmsCodeApiController.wechatUserService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wechatUserServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zhenler.eorder.food.service.IFoodService com.zhenler.microcode.service.impl.WechatUserServiceImpl.iFoodService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'foodServiceImpl': Bean with name 'foodServiceImpl' has been injected into other beans [foodPackageServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. 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.

 
如出现上诉情况, 避免报错 可以在service中添加:@Lazy(true)   例如:
	@Autowired
	@Lazy(true)
	private IFoodPackageService foodPackageService;

 
则可以解决 循环引用 导致spring boot启动报错问题。 


[注意:  尽量在涉及架构的时候 进行松耦合]
上一篇:Eclipse 报错 org.springframework.context.support.AbstractApplicationContext refresh处理


下一篇:Error creating bean with name 'XXX': Injection of autowired dependencies failed解决办法