vieyahn2017 / javaway

java on the way
5 stars 3 forks source link

1.16 springboot集成druid多数据源连接 #87

Closed vieyahn2017 closed 1 year ago

vieyahn2017 commented 5 years ago

https://blog.csdn.net/liuxiao723846/article/details/80463842 spring-boot整合mybatis和druid连接池(多数据源+动态数据源)

vieyahn2017 commented 5 years ago

实现

vieyahn2017 commented 5 years ago

参考例子
https://github.com/hn1987126/usedcar/tree/41d00a10a22961ee338a156b22a7ac448d9217bd/src/main/java/com/cn/jhsoft/usedcar/datasources
以及
https://github.com/MakerSZChina/GitRepository/blob/abc5cb3b34a548a7ffe0f7dc1bc6a957906ad35a/src/main/java/com/example/demo/config/DynamicDataSourceConfig.java

vieyahn2017 commented 5 years ago

SpringBoot 1.5.9
druid-spring-boot-starter 1.1.10
的时候的样例

spring:
#  application:
#    name: idf
  datasource:
    druid:
      da:
        url: jdbc:postgresql://8.6.5.8:20345/da
        username: user
        password: p7qWMt+9dZvnLK1gSXnS28LVUewwwwwwwwwwwwwwwwwwwwwwF7xzGHTFrDw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIweeeeeeeeeeeeeeeeeeeeeeeee/hmrSoOsubNjc4pxtN25K7Wmn84Q1JD/VAEIPK8CAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
      ds:
        url: jdbc:postgresql://8.6.5.8:20345/db
        username: users
        password: t1qj41szv60Q2fqtDNSMEhlrrrrrrrrrrrrrrrrrM2wsdKo22WLJ8HRY3lw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDQYJKrrrrrrrrrrrrrrrrrrrrrrrrrAjtiM6WJ/+/m5dAcXFMz4Nx2m4EGPruJHjt6f8gMswkkCAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
      db:
        url: jdbc:postgresql://8.6.5.8:20345/db
        username: user
        password: Lo5KeFf+YRjpz/6rrrrrrrrrrrrrrrrrrrrrrrrrroTKmewU9Gj8Q+QgtChw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrtrrrrrrrb/BrnGyCJ3LLrSNn7wDf0UCAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
      filters: config,stat,wall
      maxActive: 30
      initialSize: 1
      maxWait: 60000
      minIdle: 3
      timeBetweenEvictionRunsMillis: 60000
      minEvictableIdleTimeMillis: 300000
      validationQuery: select 'x'
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      poolPreparedStatements: true
      maxOpenPreparedStatements: 100
vieyahn2017 commented 5 years ago

升级到SpringBoot 2.0.4 druid-spring-boot-starter 1.1.10 的时候的样例
不兼容之前的通用设置了

spring:
#  application:
#    name: idf
  datasource:
    druid:
      da:
        url: jdbc:postgresql://8.6.5.8:20345/da
        username: user
        password: p7qWMt+9dZvnLK1gSXnS28LVUewwwwwwwwwwwwwwwwwwwwwwF7xzGHTFrDw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIweeeeeeeeeeeeeeeeeeeeeeeee/hmrSoOsubNjc4pxtN25K7Wmn84Q1JD/VAEIPK8CAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
        filters: config,stat,wall
        maxActive: 30
        initialSize: 1
        maxWait: 60000
        minIdle: 3
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: select 'x'
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxOpenPreparedStatements: 100
      ds:
        url: jdbc:postgresql://8.6.5.8:20345/db
        username: users
        password: t1qj41szv60Q2fqtDNSMEhlrrrrrrrrrrrrrrrrrM2wsdKo22WLJ8HRY3lw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDQYJKrrrrrrrrrrrrrrrrrrrrrrrrrAjtiM6WJ/+/m5dAcXFMz4Nx2m4EGPruJHjt6f8gMswkkCAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
        filters: config,stat,wall
        maxActive: 30
        initialSize: 1
        maxWait: 60000
        minIdle: 3
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: select 'x'
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxOpenPreparedStatements: 100
      db:
        url: jdbc:postgresql://8.6.5.8:20345/db
        username: user
        password: Lo5KeFf+YRjpz/6rrrrrrrrrrrrrrrrrrrrrrrrrroTKmewU9Gj8Q+QgtChw==
        connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrtrrrrrrrb/BrnGyCJ3LLrSNn7wDf0UCAwEAAQ==
        driver_class_name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
        filters: config,stat,wall
        maxActive: 30
        initialSize: 1
        maxWait: 60000
        minIdle: 3
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: select 'x'
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxOpenPreparedStatements: 100
vieyahn2017 commented 5 years ago

2019.2.25这个问题,排查了好久