• yml 配置数据库的多数据源配置,@DS注解 ,dynamic


    背景:项目需要pgsql 数据库与 clickhouse数据库两个数据源。

    1 pom 文件

     <dependency>
                <groupId>ru.yandex.clickhouse</groupId>
                <artifactId>clickhouse-jdbc</artifactId>
                <version>0.3.2</version>
            </dependency>
            <!-- druid连接池,clickhouse使用此连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.2.8</version>
            </dependency>
    
    
            <!-- mybatis-plus -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.3.1</version>
            </dependency>
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
                <version>3.4.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>42.2.14</version>
                <scope>runtime</scope>
            </dependency>
    

      

    c需要 druid 的数据连接池。

    其他的配合mybatisplus 和  dynamic 使用。

    2  yml 配置

    这里主要配置了这几个参数。

     例如 其他的参数配置

    dynamic:
          druid:
            initial-size: 5
            min-idle: 5
            maxActive: 20
            maxWait: 60000
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            validationQuery: SELECT 1 FROM DUAL
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            poolPreparedStatements: true
            maxPoolPreparedStatementPerConnectionSize: 20
            filters: stat,wall,slf4j
            connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000

    3 使用方式

    在 servicer层 或者 Dao层 打上注解

     

     @DS 后面写如 你在yml 配置的数据库地址的别名

    Ok,使用的方式还是比较简单明了的。

     
  • 相关阅读:
    Daily Scrum 12.9
    成员总结
    反省与深思
    M1事后分析报告--We have power to change the origin state
    PowerTeam--Alpha阶段个人贡献分及转会人员
    Pipeline Alpha版本项目展示
    js 字符串操作函数
    js与jq对数组的操作
    js 与 jq 的节点添加删除实例
    js,jq,css选择器
  • 原文地址:https://www.cnblogs.com/zq1003/p/16375463.html
Copyright © 2020-2023  润新知