Druid报错dbType not support : null, url null
问题
Druid 数据源访问连接的时候报错dbType not support : null, url null
原因
数据源配置错误
错误数据源配置
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://192.168.0.100:3306/Gblog?characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 1
min-idle: 1
max-active: 20
max-wait: 3000
validation-query: SELECT 1 FROM DUAL
test-on-borrow: false
test-on-return: false
test-while-idle: true
pool-prepared-statements: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
filters: stat,wall,slf4j
原因
我的druid绑定的是spring.datasource.druid
里面没有数据库的配置信息,数据库的配置信息在上一层,所以找不到。
@ConfigurationProperties(prefix="spring.datasource.druid")
@Bean
public DataSource druid(){
return new DruidDataSource();
}
解决方法
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
username: root
password: 123456
url: jdbc:mysql://192.168.0.100:3306/Gblog?characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 1
min-idle: 1
max-active: 20
max-wait: 3000
validation-query: SELECT 1 FROM DUAL
test-on-borrow: false
test-on-return: false
test-while-idle: true
pool-prepared-statements: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
filters: stat,wall,slf4j
将数据源的配置移到druid下即可。
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 程序员小航
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果