本文主要是介绍Spring Boot 2.0.2 + druid 多数据源报 dbType not support : null, url null 解决方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.问题:
java.lang.IllegalStateException: dbType not support : null, url nullat com.alibaba.druid.wall.WallFilter.init(WallFilter.java:159) ~[druid-1.1.5.jar:1.1.5]at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:770) [druid-1.1.5.jar:1.1.5]at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1215) [druid-1.1.5.jar:1.1.5]at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1211) [druid-1.1.5.jar:1.1.5]at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:105) [druid-1.1.5.jar:1.1.5]at
2.原因:
报错原因就是因为在DataSourceConfig中使用了
1 @Configuration2 public class DataSourceConfig {3 4 @Bean(name = "primaryDataSource")5 @Qualifier("primaryDataSource")6 @Primary7 @ConfigurationProperties(prefix = "spring.datasource.primary")8 public DataSource primaryDatasource() {9 return DataSourceBuilder.create().type(==com.alibaba.druid.pool.DruidDataSource.class==).build();
10 }
11
12 @Bean(name = "secondaryDataSource")
13 @Qualifier("secondaryDataSource")
14 @ConfigurationProperties(prefix = "spring.datasource.secondary")
15 public DataSource secondaryDataSource() {
16 return DataSourceBuilder.create().type(==com.alibaba.druid.pool.DruidDataSource.class==).build();
17 }
18 }
3.问题展示:
而在application.yml配置文件中使用了jdbc-url从而产生了错误,原有配置:
spring:datasource:type: com.alibaba.druid.pool.DruidDataSourceprimary:driver-class-name: com.mysql.cj.jdbc.Driver#jdbc-url: jdbc:mysql://localhost/test1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=falseurl: jdbc:mysql://localhost/test1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=falseusername: rootpassword: 123456# 下面为连接池的补充设置,应用到上面所有数据源中# 初始化大小,最小,最大name: primaryinitialSize: 5minIdle: 5maxActive: 20# 配置获取连接等待超时的时间maxWait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒timeBetweenEvictionRunsMillis: 60000# 配置一个连接在池中最小生存的时间,单位是毫秒minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1testWhileIdle: truetestOnBorrow: falsetestOnReturn: false# 打开PSCache,并且指定每个连接上PSCache的大小poolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙filters: stat,wall,log4j# 通过connectProperties属性来打开mergeSql功能;慢SQL记录connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000logSlowSql: true# 合并多个DruidDataSource的监控数据useGlobalDataSourceStat: truesecondary:driver-class-name: com.mysql.cj.jdbc.Driver#jdbc-url: jdbc:mysql://localhost/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=falseurl: jdbc:mysql://localhost/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=falseusername: rootpassword: 123456# 下面为连接池的补充设置,应用到上面所有数据源中# 初始化大小,最小,最大name: secondaryinitialSize: 5minIdle: 5maxActive: 20# 配置获取连接等待超时的时间maxWait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒timeBetweenEvictionRunsMillis: 60000# 配置一个连接在池中最小生存的时间,单位是毫秒minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1testWhileIdle: truetestOnBorrow: falsetestOnReturn: false# 打开PSCache,并且指定每个连接上PSCache的大小poolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙filters: stat,wall,log4j# 通过connectProperties属性来打开mergeSql功能;慢SQL记录connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000logSlowSql: true# 合并多个DruidDataSource的监控数据useGlobalDataSourceStat: true
4.解决方法:
将application.yml 配置文件中的jdbc-url改成url就行了
这篇关于Spring Boot 2.0.2 + druid 多数据源报 dbType not support : null, url null 解决方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!