Shardingsphere踩坑

项目中使用shardingsphere作为数据库中间件,之前用过4.x,发现现在最新版本是5.x,决定尝个鲜。按照官方文档配置后一直报以下错误。

Inline sharding algorithm expression cannot be null

配置完全是按照官方文档配的。

网上搜索半天也没有类似的文章,看来没法偷懒了,只能自己翻源码了!

经过读源码,找到shardingsphere读取配置的代码,

是在shardingsphere-sharding-spring-boot-starter-5.0.0-beta.jar中的
org.apache.shardingsphere.sharding.spring.boot.algorithm.ShardingAlgorithmProvidedBeanRegistry.class
调用它的父类
shardingsphere-jdbc-spring-boot-starter-infra-5.0.0-beta.jar中的
org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.class
中的registerBean()方法读取配置文件。

跟踪代码发现竟然是因为shardingAlgorithmName字段不支持下划线,可是官网例子里明明是下划线呀。

另一个问题是在shardingsphere中整合seata分布式事务,记住一定要在方法上同时加上普通事务注解@Transactional,这样分布式事务@ShardingTransactionType(TransactionType.BASE)才能生效。同时必须手工配置事务管理器,否则也不能生效。

@Configuration
@EnableTransactionManagement
public class TransactionConfig {
	
	@Bean
    public PlatformTransactionManager txManager(final DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

}

也许是因为目前5.x还处于beta版本吧。从4.x到5.x配置有了一些变化,学习了半天,加上调试解决这个问题,一整天过去了,开源软件还是坑挺多的,技术人员苦呀。好在解决了,自己留个记录 ,也是希望对别人有所帮助。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值