shardingsphere在启动的时候报错:
Caused by: java.lang.IllegalArgumentException: Type is required. at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142) at org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration.<init>(ShardingSphereAlgorithmConfiguration.java:37) at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.createAlgorithmConfiguration(AbstractAlgorithmProvidedBeanRegistry.java:88) at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.createAlgorithmConfigurations(AbstractAlgorithmProvidedBeanRegistry.java:80) at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.registerBean(AbstractAlgorithmProvidedBeanRegistry.java:67) at org.apache.shardingsphere.sharding.spring.boot.algorithm.ShardingAlgorithmProvidedBeanRegistry.postProcessBeanDefinitionRegistry(ShardingAlgorithmProvidedBeanRegistry.java:38) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:285) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:129) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:123) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ... 68 more
我的配置:
spring:
shardingsphere:
props:
sql-show: true
datasource:
names: ds_0
ds_0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://xxxx:3306/cloud_user?useUnicode=true&useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: root
rules:
sharding:
tables:
t_order:
actual-data-nodes: ds_0.t_order_${0..1} # 由数据源名 + 表名组成
table-strategy:
standard:
sharding-column: id # 分片列名称
sharding-algorithmName: t_order_inline #分片算法名称
keyGenerate-strategy:
column: id # 自增列名称,缺省表示不使用自增主键生成器
keyGeneratorName: snowflake # 分布式序列算法名称
shardingAlgorithms:
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${id % 2}
binding-tables: t_order
我已经定义了type为INLINE了,但为什么没读到?
debug查看过程:
发现它的key是这样拼的:
spring.shardingsphere.rules.sharding.tables.sharding-algorithms.t_order_inline,type
shardingAlgorithms改为sharding-algorithms
其他的可能支持驼峰式,但是shardingsphere貌似不知道,不知道是版本问题吗,我的是:
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.2</version>
</dependency>