方便更快捷的说明问题,可以按需填写(可删除)
使用环境:
Springboot+Sharding-Sphere-JDBC5.2.1(yaml配置方式)
场景、问题:
将分布式序列值配置为雪花算法生成,结果反复提示logic_db中找不到对应的keyGenerator,相关的yml配置信息如下:
spring:
shardingsphere:
mode:
type: Standalone
repository:
type: JDBC
# 配置多数据源
datasource:
# 为多个数据源配置别名
names: ds0,ds1
# 配置第一个数据源的详情
ds0:
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db_sharding_01?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
username: root
password: 123
# 配置第二个数据源的详情
ds1:
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db_sharding_02?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
username: root
password: 123
# 执行时显示SQL语句
props:
# 日志显示具体的SQL
sql-show: true
# 配置分片规则
rules:
# 配置分片策略
sharding:
# 配置所有分片表
tables:
# 首先配置商品表的分片策略
shoping:
# 声明商品表所在的真实数据节点
actual-data-nodes: ds$->{0..1}.shoping_0$->{1..2}
database-strategy:
standard:
sharding-columns: shoping_id
sharding-algorithm-name: d-shop-inline
table-strategy:
standard:
sharding-algorithm-name: t-shop-inline
key-generators:
shoping_id_gs:
type: SNOWFLAKE
props:
worker-id: 111
key-generate-strategy:
column: shoping_id
keygenerator-name: shoping_id_gs
sharding-algorithms:
d-shop-inline:
type: INLINE
props:
algorithm-expression: ds$->{shoping_id % 2}
t-shop-inline:
type: INLINE
props:
algorithm-expression: shoping_0$->{shoping_id % 2}
已进行操作:
多次调整后依旧无法正常启动,debug调试发现配置的keyGenerator在Map<String, YamlTableRuleConfiguration>中是存在的,但就是反复抛出找不到这个分布式序列的错误。
现状:
Caused by: java.lang.IllegalStateException: Can not find keyGenerator xxx
in database logic_db
.