本文介绍基于yaml配置文件的全配置分库分表引擎整合,无需java代码编写配置config,下载源代码目的是为了要里面的yaml配置文件,并不需要安装编译shardingsphere。
一、官网下载apache-shardingsphere-5.2.1-src.zip,里面的test项目下面有很多yaml配置文件可以参考。
二、更改ruoyi-admin下面的application-druid.yml并创建application-sharding.yml,在application-druid.yml最下面增加:
spring:
datasource:
。。。。。。(原有配置省略)
shardingsphere:
configLocation: application-sharding.yml
三、这是我的application-sharding.yml配置文件,请大家参考:
# 分库分表配置 dataSources: ds_0: dataSourceClassName: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ds_0?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: root maxTotal: 100 ds_1: dataSourceClassName: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ds_1?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: root maxTotal: 100 rules: - !TRANSACTION defaultType: LOCAL - !SHARDING tables: tmp_order: actualDataNodes: ds_${0..1}.tmp_order_${0..1} tableStrategy: standard: shardingColumn: order_id shardingAlgorithmName: tmp_order_inline keyGenerateStrategy: column: order_id keyGeneratorName: snowflake tmp_order_item: actualDataNodes: ds_${0..1}.tmp_order_item_${0..1} tableStrategy: standard: shardingColumn: order_id shardingAlgorithmName: tmp_order_item_inline keyGenerateStrategy: column: order_item_id keyGeneratorName: snowflake sys_orde