可能的原因:

  1. 配置文件中的属性名拼写错误或大小写错误。
  2. 配置文件中的属性值格式不正确。
  3. 依赖库版本冲突导致配置不生效。

正确的配置例子:

spring:
  shardingsphere:
    datasource:
      names: ds0,ds1
      ds0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/db0?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
        username: root
        password: root
      ds1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/db1?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
        username: root
        password: root
    sharding:
      tables:
        user:
          actual-data-nodes: ds$->{0..1}.user_$->{0..15}
          table-strategy:
            inline:
              sharding-column: id
              algorithm-expression: user_$->{id % 16}

这个配置文件中定义了两个数据源ds0和ds1,分别对应了两个数据库db0和db1。在sharding配置中,定义了一个user表,并使用了分表策略,将数据按照id字段进行分片,分成16个表。具体的分表规则是:根据id模16的结果,选择user_0到user_15中的一个表进行存储

ruoyi框架在yml中配置Sharding分表不生效的原因。并举个正确的配置例子

原文地址: https://www.cveoy.top/t/topic/fhzq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录