ShardingSphere JDBC 不支持不同类型的源测试
废话少说。
ShardingSphere JDBC官方配置文档
https://shardingsphere.apache.org/document/legacy/4.x/document/cn/manual/sharding-jdbc/configuration/config-java/
环境说明
<spring.boot.version>2.1.13.RELEASE</spring.boot.version>
<shardingsphere.version>4.1.1</shardingsphere.version>
<mybatis.spring.boot.starter.version>2.1.1</mybatis.spring.boot.starter.version>
<druid.spring.boot.starter.version>1.1.22</druid.spring.boot.starter.version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.RELEASE</version>
</parent>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot.starter.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.spring.boot.starter.version}</version>
</dependency>
配置说明
shardingsphere:
datasource:
names: customer-master,customer-slave,dhep-master
customer-master:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/creditcloud_customer?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
username: user_cloud_cus
password: ENC(MqKzNeoGyIlqDkOaEFTz10b/98ZYdcu1)
type: com.alibaba.druid.pool.DruidDataSource
initial-size: 10
min-idle: 10
max-active: 30
test-on-borrow: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
customer-slave:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3308/creditcloud_customer?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
username: user_cloud_cus
password: ENC(MqKzNeoGyIlqDkOaEFTz10b/98ZYdcu1)
type: com.alibaba.druid.pool.DruidDataSource
initial-size: 10
min-idle: 10
max-active: 30
test-on-borrow: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
dhep-master:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://127.0.0.1:1443;database=DHEP
username: dhep_sa
password: ENC(/8Jt1gBaz2aT2TP6ru0/CW5md2V/yDVR)
masterslave:
load-balance-algorithm-type: round_robin
master-data-source-name: customer-master
slave-data-source-names: customer-slave
name: ds_ms
sharding:
master-slave-rules:
ds_db01:
masterDataSourceName: customer-master
slaveDataSourceNames:
- customer-slave
ds_db02:
masterDataSourceName: dhep-master
slaveDataSourceNames: none
default-data-source-name: ds_db01
default-database-strategy:
hint:
algorithm-class-name: com.dahuatech.creditcloud.customer.core.sharding.DatasourceRoutingAlgorithm
props:
sql.show: false
结论:
org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter.java
ardingjdbc.jdbc.adapter.AbstractDataSourceAdapter.java
[外链图片转存中...(img-wPwvoOSL-1602920450925)]
此处是不同数据源的校验。不支持不同类型的数据源共用。