一开始配置连接池以及多数据源信息是这样的
datasource:
druid:
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 100
dynamic:
primary: master
strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.
datasource:
druid:
initial-size: 5
max-active: 5
min-idle: 1
max-wait: 60000
master:
url: jdbc:postgresql://ip:5431/test?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=GMT%2B8
username: postgres
password: SmartAgriculture123.
driver-class-name: org.postgresql.Driver
bigdata:
url: jdbc:mariadb://ip:10030/test?characterEncoding=utf-8&useSSL=false&useTimezone=true
username: root
password: geovis@123
driver-class-name: org.mariadb.jdbc.Driver
但是启动时会报错
明明配置了,但是仍然报错,一时找不到原因,
问题解决:找到博客 方案来源
不同数据库的数据判断语句不同,语句可查看该连接
最终解决问题后配置如下:
datasource:
druid:
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
validationQuery: select 'x'
poolPreparedStatements: true
maxOpenPreparedStatements: 100
dynamic:
primary: master
strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.
datasource:
druid:
initial-size: 5
max-active: 5
min-idle: 1
max-wait: 60000
master:
url: jdbc:postgresql://ip:5431/test?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=GMT%2B8
username: postgres
password: SmartAgriculture123.
driver-class-name: org.postgresql.Driver
druid:
validationQuery: select version()
bigdata:
url: jdbc:mariadb://ip:10030/test?characterEncoding=utf-8&useSSL=false&useTimezone=true
username: root
password: geovis@123
driver-class-name: org.mariadb.jdbc.Driver
druid:
validationQuery: select 1