# ds
**Repository Path**: tangwei123456/ds
## Basic Information
- **Project Name**: ds
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-07-13
- **Last Updated**: 2021-07-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 多数据源切换,操作步骤
## 1、引入本依赖 com.legend.ds:0.0.1
```
com.legend
ds
0.0.2
```
## 2、去掉legend各个module中的dynamic-datasource-spring-boot-starter依赖
```
com.legend.biz
legend-sdk
0.0.2-SNAPSHOT
com.baomidou
dynamic-datasource-spring-boot-starter
```
## 3、添加配置:
```
lanzhen:
ds:
enable: true #这儿配置数据源是否根据租户切换,一般情况下都是为true,如果为false,就会走下面配置的default数据源
tenant-ds:
default:
url: jdbc:mysql://192.168.2.235:31940/te1?useSSL=false&useUnicode=true&characterEncoding=utf-8&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: tangwei123456
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
tenant515797:
url: jdbc:mysql://192.168.2.235:31940/te1?useSSL=false&useUnicode=true&characterEncoding=utf-8&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: tangwei123456
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
tenant462179:
url: jdbc:mysql://192.168.2.235:31940/te2?useSSL=false&useUnicode=true&characterEncoding=utf-8&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: tangwei123456
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
```
## 4、在入口文件中添加注解:
```
@EnableLanzhenDynamicDataSource //这个注解是打开多数据源,一旦打开了,就不走系统的默认数据源了,同时会注册上面写的所有的数据源。idea的终端会有提示
@ComponentScan({
"com.legend.biz.mes",
"com.legend.ds"
})
```