zoukankan      html  css  js  c++  java
  • sharding jdbc(sphere) 3.1.0 spring boot配置

      sharding jdbc 2.x系列详解参见https://www.cnblogs.com/zhjh256/p/9221634.html

      最近将sharding jdbc的配置从xml切换到了spring boot。首先引入依赖:

                <dependency>
                    <groupId>io.shardingsphere</groupId>
                    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
                    <version>3.1.0</version>
                </dependency>

      然后按照https://shardingsphere.apache.org/document/legacy/3.x/document/en/manual/sharding-jdbc/configuration/config-spring-boot/配置即可,基本上和xml配置是一样的。

      需要注意的是,2.x版本占位符是${},如下:

        <sharding:inline-strategy id="orderTableStrategy" sharding-column="order_id" algorithm-expression="t_order_${order_id % 2}" />

      3.x版本则是$->{},原因是跟spring占位符冲突,如下:

    sharding.jdbc.config.sharding.tables.ibf_acco_confirm.actual-data-nodes=ds$->{0..1}_$->{0..1}.ibf_acco_confirm

      规则:

    sharding.jdbc.config.sharding.tables.ibf_acco_confirm.actual-data-nodes=ds$->{0..1}.ibf_acco_confirm
    # 分库策略,定义了目标库列表,没有定义分库策略的,默认为default-database-strategy,实际上分库策略应该就一种,所以应不定义才对
    sharding.jdbc.config.sharding.tables.ibf_acco_confirm.database-strategy.hint.algorithm-class-name=com.hundsun.ta.tabase.sharding.DatabaseShardingAlgorithmByHint 
    # 表的目标库列表
    sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds$->{0..1}.t_order_item$->{0..1}
    # 分表策略 sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item$->{order_id % 2}
    # 自定生成id值的列,一般用ID中心,不应使用具体框架的 sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
    # 主子表关系定义 #sharding.jdbc.config.sharding.binding-tables=t_order,t_order_item
    # 广播表,既不在sharding.jdbc.config.sharding.tables定义,又没有定义在broadcast-tables定义的就是全局表
    #sharding.jdbc.config.sharding.broadcast-tables=t_config
    # 默认的分库策略,一般不应使用行内算法(groovy的),建议使用algorithm-class-name
    sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id 
    sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression=ds$->{user_id % 2}

    参考:

      3.1.0系列:https://shardingsphere.apache.org/document/legacy/3.x/document/en/manual/sharding-jdbc/configuration/config-spring-boot/

      4.0系列:https://shardingsphere.apache.org/document/current/cn/manual/sharding-jdbc/configuration/config-spring-boot/

  • 相关阅读:
    力扣学习计划图床01
    一篇文章带你初步了解C++重载机制
    解决Github Gist无法访问问题
    VScode解决文件乱码问题,调整文件编码
    六、angular 生成二维码
    五、angularjs在进入界面前加载数据
    四、angularjs 如何在页面没有登录的情况下阻止用户通过更改url进入页面--$stateChangeStart
    三、angularjs上传图片
    二、单页应用如何调用微信接口和手机端的一些方法?
    二、Flex 布局教程:实例篇
  • 原文地址:https://www.cnblogs.com/zhjh256/p/12018352.html
Copyright © 2011-2022 走看看