spring service层 循环引用问题。

来源:互联网 发布:免费群发短信软件 编辑:程序博客网 时间:2024/06/06 15:40
报错信息如下:
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;
则可以解决 循环引用 导致tomcat启动报错问题。 此为解决方案的一种 但是根本问题并没有得到解决。 尽量在涉及架构的时候 进行松耦合
原创粉丝点击