我有两个实现层,然后相互注入对方(orderInfoService、messageService)
在orderInfoService 注入 messageService
在messageService 注入orderInfoService
出现循环依赖问题具体错误如下:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderEvaluateStatisticsServiceImpl': Unsatisfied dependency expressed through field 'orderInfoService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'orderInfoServiceImpl': Bean with name 'orderInfoServiceImpl' has been injected into other beans [messageLogServiceImpl,callRecordServiceImpl,shopInfoServiceImpl] 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.
但是我在本地运行并没有出现问题、只是服务器部署出现。
has been injected into other beans 从字面上意义可以了解出,存在多版本的不同实例(topicService)
具体原因不知
解决方案
在注入@Autowired 下加@Lazy 注解即可(两边都加比较保险)