springboot多数据源启动循环依赖The dependencies of some of the beans in the application context form a cycle

使用druid多数据源时,项目启动出现数据源循环依赖,

sprintboot 低版本可以使用 spring.datasource.initialize=false (默认为true) 来解决,升级到sprintboot2.1.2后就发现被启用了

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

在启动类上增加这个属性即可!

Description:

The dependencies of some of the beans in the application context form a cycle:

   sswcDeviceServiceImp (field private com.boot.modules.mapper.SswcDeviceMapper com.boot.modules.service.imp.SswcDeviceServiceImp.mapper)
      ↓
   sswcDeviceMapper defined in file [C:\work\Eclipse202003WorkSpace\SpringHtmlJspTest\target\classes\com\boot\modules\mapper\SswcDeviceMapper.class]
      ↓
   sqlSessionFactory defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]
┌─────┐
|  dataSource defined in class path resource [com/boot/base/db/DynamicDataSourceConfig.class]
↑     ↓
|  masterDataSource defined in class path resource [com/boot/base/db/DynamicDataSourceConfig.class]
↑     ↓
|  org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘
 

你可能感兴趣的:(springboot,数据库)