也就分为逻辑datasource定义, 真实的datasource定义.对于每个逻辑表,定义分库分表规则,如果需要生成分布式key,定义key的生成算法.分别对应spring.shardingsphere.datasource.
前缀和spring.shardingsphere.rules.sharding
前缀.
对于SNOWFLAKE要注意数据库的字段类型要bigint,int不够放.
启动报错***************************APPLICATION FAILED TO START***************************Description:An attempt was made to call a method that does not exist. The attempt was made from the following location:org.apache.shardingsphere.infra.util.yaml.constructor.ShardingSphereYamlConstructor$1.<init>(ShardingSphereYamlConstructor.java:44)The following method did not exist:'void org.apache.shardingsphere.infra.util.yaml.constructor.ShardingSphereYamlConstructor$1.setCodePointLimit(int)'The calling methods class, org.apache.shardingsphere.infra.util.yaml.constructor.ShardingSphereYamlConstructor$1, was loaded from the following location:jar:file:/.m2/repository/org/apache/shardingsphere/shardingsphere-infra-util/5.2.1/shardingsphere-infra-util-5.2.1.jar!/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor$1.classThe called methods class, org.apache.shardingsphere.infra.util.yaml.constructor.ShardingSphereYamlConstructor$1, is available from the following locations:jar:file:/.m2/repository/org/apache/shardingsphere/shardingsphere-infra-util/5.2.1/shardingsphere-infra-util-5.2.1.jar!/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor$1.classThe called methods class hierarchy was loaded from the following locations:null: file:/.m2/repository/org/apache/shardingsphere/shardingsphere-infra-util/5.2.1/shardingsphere-infra-util-5.2.1.jarorg.yaml.snakeyaml.LoaderOptions: file:/.m2/repository/org/yaml/snakeyaml/1.30/snakeyaml-1.30.jarAction:Correct the classpath of your application so that it contains a single, compatible version of org.apache.shardingsphere.infra.util.yaml.constructor.ShardingSphereYamlConstructor$1
很明显的一个以来冲突问题, 主要是这行代码:
public ShardingSphereYamlConstructor(final Class<?> rootClass) {super(rootClass, new LoaderOptions() {{setCodePointLimit(Integer.MAX_VALUE);}});ShardingSphereYamlConstructFactory.getInstances().forEach(each -> typeConstructs.put(each.getType(), each));ShardingSphereYamlShortcutsFactory.getAllYamlShortcuts().forEach((key, value) -> addTypeDescription(new TypeDescription(value, key)));this.rootClass = rootClass;}
snakeyaml的版本冲突,使用的版本中LoaderOptions
没有setCodePointLimit
这个方法.使用的springboot的依赖的是1.30.0
,显式依赖1.33.0
即可.
<dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>1.33</version></dependency>
配置错误导致的报错这类报错种类比较多比如
DataNodesMissedWithShardingTableException
ShardingRuleNotFoundException
InconsistentShardingTableMetaDataException
这种就要看看对应的错误和配置.
不过有点奇怪的是一些错误没有打出详细的报错信息.比如:
Caused by: org.apache.shardingsphere.sharding.exception.metadata.DataNodesMissedWithShardingTableException: null at org.apache.shardingsphere.sharding.rule.TableRule.lambda$checkRule$4(TableRule.java:246) ~[shardingsphere-sharding-core-5.2.1.jar:5.2.1] at org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:41) ~[shardingsphere-infra-util-5.2.1.jar:5.2.1] at org.apache.shardingsphere.sharding.rule.TableRule.checkRule(TableRule.java:245) ~[shardingsphere-sharding-core-5.2.1.jar:5.2.1]
看了下是基类没调用super,导致message没有值.看了下这个已经在master分支修好了:
经验总结扩展阅读
- 2022江苏中职学业水平考试考生健康应试须知
- 三谷424洗发水成分表_三谷进化论424洗发水成分表
- 飞行员工资一般多少 最新薪资水平
- R7 5800U核显相当于什么显卡_R7 5800U核显什么水平
- 天玑1100相当于骁龙多少处理器_天玑1100相当于骁龙什么水平
- 天玑810相当于什么处理器_天玑810处理器什么水平
- 骁龙870什么水平_骁龙870相当于什么水平
- 退休6500元是什么水平 65到74岁养老金能有多少钱
- rx6600xt显卡相当于什么n卡_rx6600xt显卡什么水平
- 迪美露芦荟胶成分表是什么?