尊敬的各位开发者,各位点进来的前辈,你们好。
我是sharding-jdbc的初学者,现在遇到了一个问题无法解决,在查阅了网上文章后也没有找到方法。可能问题比较naive,也请大家多多包涵。
问题是这样的:我目前的项目中,配置方式是springboot的配置方式。sharding-jdbc提供的配置文件中,比如“sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression”这条属性,是负责配置分库的算法的。但是目前我所知的是,这条属性现在只能采用sharding-jdbc提供的表达式来配置算法,比如test_${id%2}这样。
然而我希望通过自己手动实现ShardingAlgorithm接口的方式来实现算法,但是网上的文章中,这种实现的配置方式只有spring命名空间和java config两种,没有关于springboot这种配置方式的。请问,springboot这种配置方式是否支持手动实现的算法呢?如果支持,那么我该怎么做?
最后谢谢大家。
https://github.com/shardingjdbc/sharding-jdbc-example
可以看他们的官方例子,里面有PreciseModuloDatabaseShardingAlgorithm.java
这个是他们的wiki
http://shardingjdbc.io/docs/01-start/quick-start/
@hwck
麻烦您了,万分感谢。
这是sharding-jdbc结合spring-boot的例子:https://github.com/shardingjdbc/sharding-jdbc-example/tree/dev/sharding-jdbc-spring-boot-example/sharding-jdbc-spring-boot-data-mybatis-example
我再截取一下这个配置文件的代码:
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression=ds_${user_id % 2}
这个代码中,实现模2算法所用的是表达式。但是如果我想通过实现ShardingAlgorithm的接口来实现算法的话,能够在这里实现配置吗?
@Frodez 可以啊,你要自己指定算法类就可以了
Most helpful comment
https://github.com/shardingjdbc/sharding-jdbc-example
可以看他们的官方例子,里面有PreciseModuloDatabaseShardingAlgorithm.java
这个是他们的wiki
http://shardingjdbc.io/docs/01-start/quick-start/