springboot整合多个达梦数据源

直接上干货!

pom.xml文件

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>com.damenggroupId>
            <artifactId>Dm8JdbcDriver18artifactId>
            <version>8.1.1.49version>
        dependency>
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>dynamic-datasource-spring-boot-starterartifactId>
            <version>3.1.0version>
        dependency>

yaml文件配置:

spring:
  datasource:
    dynamic:
      primary: db_realname # 配置默认数据库
      datasource:
        db_realname:
          driver-class-name: dm.jdbc.driver.DmDriver
          type: com.alibaba.druid.pool.DruidDataSource
          url: jdbc:dm://localhost:5237?schema=smartsitetest2
          username: TEST
          password: 123456789
          #连接池
          druid:
            # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
            connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
            # 初始化大小,最小,最大
            initial-size: 5
            max-active: 50
            min-idle: 5
            # 配置获取连接等待超时时间
            max-wait: 80000
            # 打开PSCache,并且指定每个连接上PSCache的大小
            pool-prepared-statements: true
            max-pool-prepared-statement-per-connection-size: 20
            validation-query: SELECT 'x'
            validation-query-timeout: 60000
            test-on-borrow: true
            test-on-return: true
            test-while-idle: true
            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
            time-between-eviction-runs-millis: 60000
            min-evictable-idle-time-millis: 300000
            log-abandoned: true
            remove-abandoned: true
            remove-abandoned-timeout: 1800
            filters: stat
        db_iot:
          driver-class-name: dm.jdbc.driver.DmDriver
          type: com.alibaba.druid.pool.DruidDataSource
          url: jdbc:dm://localhost:5237?schema=smartsiteiottest
          username: TEST
          password: 123456789
          #连接池
          druid:
            # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
            connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
            # 初始化大小,最小,最大
            initial-size: 5
            max-active: 50
            min-idle: 5
            # 配置获取连接等待超时时间
            max-wait: 80000
            # 打开PSCache,并且指定每个连接上PSCache的大小
            pool-prepared-statements: true
            max-pool-prepared-statement-per-connection-size: 20
            validation-query: SELECT 'x'
            validation-query-timeout: 60000
            test-on-borrow: true
            test-on-return: true
            test-while-idle: true
            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
            time-between-eviction-runs-millis: 60000
            min-evictable-idle-time-millis: 300000
            log-abandoned: true
            remove-abandoned: true
            remove-abandoned-timeout: 1800
            filters: stat
  autoconfigure:
    exclude:  com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
#mybatis
mybatis-plus:
  mapper-locations: classpath*:/mapper/*.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: com.xxx.entity
  global-config:
    #数据库相关配置
    db-config:
      #主键类型  AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
      id-type: AUTO
      #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
      field-strategy: NOT_NULL
      #驼峰下划线转换
      column-underline: true
      logic-delete-value: -1
      logic-not-delete-value: 0
    banner: false
  #原生配置
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    call-setters-on-nulls: true
    jdbc-type-for-null: 'null'
    #打印SQL语句
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#日志级别
logging:
  level:
    root: INFO
    org.springframework.web.servlet.DispatcherServlet: DEBUG
  file:
    path: logs



SQL语句符合DM的语法就行,本人亲测通过,记录一下,帮助别人。

你可能感兴趣的:(Java,spring,boot,java,数据库)