oracle+TDenging多数据源配置

本文介绍了如何在SpringBoot项目中使用dynamic-datasource插件配置和管理多个数据源,包括Druid和TAOS数据库连接,以及如何在Mapper接口中通过注解动态切换数据源。
摘要由CSDN通过智能技术生成

使用dynamic-datasource配置多数据源:

引入mavne:

            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
                <version>3.5.1</version>
            </dependency>

配置数据源:

这里要注意TDengine数据库默认连接状态sql语句是select server_status()不指定的话启动会报错!

spring:
  datasource:
    dynamic:
      druid:
        initial-size: 5
        min-idle: 5
        maxActive: 20
        # 配置获取连接等待超时的时间
        maxWait: 60000
        # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
        timeBetweenEvictionRunsMillis: 6000
        # 配置一个连接在池中最小生存的时间,单位是毫秒
        minEvictableIdleTimeMillis: 60000
        # 配置一个连接在池中最大生存的时间,单位是毫秒
        maxEvictableIdleTimeMillis: 900000
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        # 打开PSCache,并且指定每个连接上PSCache的大小
        poolPreparedStatements: true
        maxPoolPreparedStatementPerConnectionSize: 20
      primary: master #设置默认的数据源或者数据源组,默认值即为master
      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
      datasource:
        master:
          driver-class-name: oracle.jdbc.OracleDriver
          username: xxxx
          password: xxxx
          url: jdbc:xxxx:@xxxx:xxxx:xxxx
        taos:
          driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
          username: root
          password: taosdata
          url: jdbc:TAOS-RS://xxxx:6030/xxxx
          hikari:
            connection-test-query: select server_status() # 连接是否有效的查询语句

使用的时候用@DS("taos")来切换数据源:

@Mapper
@DS("taos")
public interface TestMapper {

    List<CollectionData> testCollection();
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值