springboot整合多个达梦数据源

直接上干货!

pom.xml文件

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.dameng</groupId>
            <artifactId>Dm8JdbcDriver18</artifactId>
            <version>8.1.1.49</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
            <version>3.1.0</version>
        </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的语法就行,本人亲测通过,记录一下,帮助别人。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值