新创建项目配置动态数据源后项目启动时出现类循环依赖的情况,具体异常如下:
Description:
The dependencies of some of the beans in the application context form a cycle:
customSubException (field private com.jy.insurance.mapper.RarLogMapper com.jy.insurance.bus.CustomSubException.rarLogMapper)
↓
rarLogMapper defined in file [D:\DevelopSpace\devSpace\main_factory_dev\zhuopu-policy\zhuopu-services\zhuopu-insure-toolkit\target\classes\com\zhuopu\insurance\mapper\RarLogMapper.class]
↓
sqlSessionFactory defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]
┌─────┐
| dynamicDataSource defined in class path resource [com/zhuopu/common/config/database/DruidConfig.class]
↑ ↓
| masterDataSource defined in class path resource [com/zhuopu/common/config/database/DruidConfig.class]
↑ ↓
| org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘
起初一直以为是jar包冲突引起的(新项目是在老项目基础上改动的,将springboot版本进行了升级),在各种分析包依赖后最终无果而终,后来突然留意到异常的最后一行 ,心生一计既然包依赖是springboot autoconfigure中对数据源和自动配置引起的,那么忽略掉这个配置是不是就OK了?心动不如行动,果断排除了对数据源的自动配置
,再次启动一切OK。
PS:再出现这种莫名的异常一定要先认真分析异常原因再下结论,不然会抗死自己的。