已有springboot项目加入sharding5框架

注意点

配置druid连接池的时候,不要用下面这中配置,因为程序启动的时候,会去找spring.datasource中的配置,由于我是删除了该配置,所以启动会报错,解决方法:

在这里插入图片描述
换成在这里插入图片描述
单库分表配置。

spring: 
    #指定数据源
  shardingsphere:
    datasource:
      names: ds0 #可多库配置
      #数据源的具体配置
      ds0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC
        username: root
        password: 123456
    #具体的分片规则
    rules:
      sharding:
        tables:
          table_name: #用来写sql的虚拟表名
            actual-data-nodes: ds0.table_name$->{0..99} #物理表名
            table-strategy:
              standard:
                sharding-column: id
                sharding-algorithm-name: table-inline
          table_name_name: #用来写sql的虚拟表名
            actual-data-nodes: ds0.table_name_name$->{0..1} #物理表名
            table-strategy:
              standard:
                sharding-column: id
                sharding-algorithm-name: table-inline #配置
        #分片算法
        sharding-algorithms:
          table-inline:
            type: HASH_MOD
            props:
              sharding-count: 2
    #显示执行的sql语句
    props:
      sql-show: true
      sql-comment-parse-enabled: true
    mode:
      type: Memory
  main:
    allow-bean-definition-overriding: true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值