shardingphere Sharding count cannot be null解决方案
- 问题背景
- 解决方案
- Lyric: 我知道坚持要走
问题背景
使用shardingphere分表分库时,出现分表算法设置错误
Caused by: java.lang.IllegalArgumentException: Sharding count cannot be null.at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142)at org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm.getShardingCount(ModShardingAlgorithm.java:52)at org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm.init(ModShardingAlgorithm.java:48)at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)... 200 common frames omitted
2023-11-03 13:48:14.179 INFO [main][] c.a.d.p.DruidDataSource.init(DruidDataSource.java:998): {dataSource-2,master} inited
2023-11-03 13:48:14.179 INFO [main][] c.b.d.d.DynamicRoutingDataSource.addDataSource(DynamicRoutingDataSource.java:148): dynamic-datasource - add a datasource named [sharding] success
2023-11-03 13:48:14.180 INFO [main][] c.b.d.d.DynamicRoutingDataSource.addDataSource(DynamicRoutingDataSource.java:148): dynamic-datasource - add a datasource named [master] success
2023-11-03 13:48:14.180 INFO [main][] c.b.d.d.DynamicRoutingDataSource.afterPropertiesSet(DynamicRoutingDataSource.java:228): dynamic-datasource initial loaded [2] datasource,primary datasource named [master]
解决方案
shardingphere5.1.1版本之前是不能使用下划线 _ 的,5.1.1版本可以使用下划线
如果使用5.0.0版本,就使用alg-mod
spring.shardingsphere.rules.sharding.sharding-algorithms.alg-mod.props.sharding-count=2048
如果使用5.1.1版本,可以使用alg_mod,也可以使用alg-mod
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_mod.props.sharding-count=2048
作为程序员第 249 篇文章,每次写一句歌词记录一下,看看人生有几首歌的时间,wahahaha …