menu 李昊天的个人博客
Druid报错dbType not support : null, url null
36 浏览 | 2020-06-10 | 分类:项目问题解决汇总 | 标签:数据库,SpringBoot,Druid,JDBC

问题

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下即可。

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

发表评论

email
web

全部评论 (暂无评论)

info 还没有任何评论,你来说两句呐!