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

 

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

 

 

 

1 pom 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<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,使用的方式还是比较简单明了的。

 
posted @   未确定  阅读(3163)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示