项目场景:
某项目引用其他starter内 Util 工具类
问题描述
项目A启动没有问题;项目B引用starter抛出工具类抛出异常:
Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘billController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘billServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘driverBillListQryExe’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘tmsDataScopeThreadLocalUtil’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘tmsDataScopeTools’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userTools’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com.base.starter.redis.config.MFStartRedisSimpleConfig’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘MFCacheManagerConfig’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘mfRedisTemplate’: Requested bean is currently in creation: Is there an unresolvable circular reference?
翻译:所需的bean目前正在创建中:是否存在不可解析的循环引用?
原因分析:
1,项目A引入没问题,项目B有问题,大概率不是starter自身的问题;
2,没有扫包? 并不是
3.检查项目A和项目B在使用上有什么区别, 完全一致
解决方案:
经过3h的查找,最后发现还是扫包的问题;虽然scan了所需的package,但是顺序有问题,
如下,最后scan的"com.component"
@SpringBootApplication(scanBasePackages = {
"com.***",
"com.***",
"com.***",
"com.***",
"com.component",
})
顺序更改一下问题解决,成功启动
@SpringBootApplication(scanBasePackages = {
"com.component",
"com.***",
"com.***",
"com.***",
})
Requested bean is currently in creation: Is there an unresolvable circular reference?
说明bean的加载顺序有问题