Error creating bean with name ‘dataSource‘ 、 Failed to determine a suitable driver class

项目场景:

sharding-jdbc和SpringBoot整合,使用druid数据源,使用<artifactId>druid-spring-boot-starter</artifactId>

问题描述:

启动或测试出现初始化数据源( Init DruidDataSource)时报错。

Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

原因分析:

1.sharding-jdbc-spring-boot-starter与druid-spring-boot-starter版本不匹配

2.druid-spring-boot-starter会在启动时自动从配置文件生成datasource,且没有配置datasource信息

解决方案:

1.使用@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})排除初始化加载生成datasource

2.不使用<artifactId>druid-spring-boot-starter</artifactId>包依赖,使用<artifactId>druid</artifactId>包依赖

3.调整<artifactId>druid-spring-boot-starter</artifactId><artifactId>sharding-jdbc-spring-boot-starter</artifactId>的版本。

上一篇:Kubernetes(4) Harbor仓库搭建


下一篇:NDK编译报错 java.lang.NullPointerException (no error message)