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/

  • 相关阅读:
    IIS和ASP.NET2.0
    VS.NET里关于不能够使用向导的问题
    CodeFile
    判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
    托管和非托管资源
    ASP.NET 2.0页面框架的几处变化
    导出QQWry.Dat中IP地址到文件[C#]
    面向对象在数据库应用程序中的应用(dotNet)
    如何取得IP/用户名等信息
    验证Email是否真正存在(上)
  • 原文地址:https://www.cnblogs.com/zhjh256/p/12018352.html
Copyright © 2011-2022 走看看