#------------------------基本配置 # 应用名称 spring.application.name=sharging-jdbc-demo # 开发环境设置 spring.profiles.active=dev # 内存模式 spring.shardingsphere.mode.type=Memory # 打印SQl spring.shardingsphere.props.sql-show=true #------------------------数据源配置 # 配置真实数据源 spring.shardingsphere.datasource.names=server-user,server-order0,server-order1 # 配置第 1 个数据源 spring.shardingsphere.datasource.server-user.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.server-user.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.server-user.jdbc-url=jdbc:mysql://192.168.100.201:3301/db_user spring.shardingsphere.datasource.server-user.username=root spring.shardingsphere.datasource.server-user.password=123456 # 配置第 2 个数据源 spring.shardingsphere.datasource.server-order0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.server-order0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.server-order0.jdbc-url=jdbc:mysql://192.168.100.201:3310/db_order spring.shardingsphere.datasource.server-order0.username=root spring.shardingsphere.datasource.server-order0.password=123456 # 配置第 3 个数据源 spring.shardingsphere.datasource.server-order1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.server-order1.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.server-order1.jdbc-url=jdbc:mysql://192.168.100.201:3311/db_order spring.shardingsphere.datasource.server-order1.username=root spring.shardingsphere.datasource.server-order1.password=123456 #------------------------标准分片表配置(数据节点配置) # 由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持 inline 表达式。 # 缺省表示使用已知数据源与逻辑表名称生成数据节点,用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况 spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=server-user.t_user # server-order0.t_order0,server-order0.t_order1,server-order1.t_order0,server-order1.t_order1 spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=server-order$->{0..1}.t_order$->{0..1} #------------------------分库策略,缺省表示使用默认分库策略,以下的分片策略只能选其一 # 用于单分片键的标准分片场景 # 分片列名称 spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-column=user_id # 分片算法名称 spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-algorithm-name=alg_mod #------------------------分表策略 # 用于单分片键的标准分片场景 # 分片列名称 spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_no # 分片算法名称 spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=alg_hash_mod #------------------------分片算法配置 # 行表达式分片算法 # 分片算法类型 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_inline_userid.type=INLINE # 分片算法属性配置 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_inline_userid.props.algorithm-expression=server-order$->{user_id % 2} # 取模分片算法 # 分片算法类型 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_mod.type=MOD # 分片算法属性配置 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_mod.props.sharding-count=2 # 哈希取模分片算法 # 分片算法类型 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_hash_mod.type=HASH_MOD # 分片算法属性配置 spring.shardingsphere.rules.sharding.sharding-algorithms.alg_hash_mod.props.sharding-count=2 #------------------------分布式序列策略配置 # 分布式序列列名称 spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=id # 分布式序列算法名称 spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=alg_snowflake #------------------------分布式序列算法配置 # 分布式序列算法类型 spring.shardingsphere.rules.sharding.key-generators.alg_snowflake.type=SNOWFLAKE # 分布式序列算法属性配置 #spring.shardingsphere.rules.sharding.key-generators.alg_snowflake.props.xxx=