该错误提示是因为Sharding-JDBC在加载Sharding算法时,没有找到对应的实现类。具体解决方案如下:

  1. 确认Sharding-JDBC的版本是否正确。需要使用Sharding-JDBC 4.0及以上版本。

  2. 确认依赖是否正确,需要引入sharding-jdbc-core和sharding-jdbc-spring-boot-starter两个依赖。例如:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-core</artifactId>
    <version>4.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.1.1</version>
</dependency>
  1. 确认Sharding-JDBC的配置是否正确。例如:
spring:
  shardingsphere:
    datasource:
      names: ds0,ds1
      ds0:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/test0?useSSL=false
        username: root
        password: root
      ds1:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/test1?useSSL=false
        username: root
        password: root
    sharding:
      tables:
        user:
          actual-data-nodes: ds$->{0..1}.user_$->{0..2}
          table-strategy:
            inline:
              sharding-column: user_id
              algorithm-expression: user_$->{user_id.longValue() % 3}
          key-generator:
            type: SNOWFLAKE
            column: user_id
      default-database-strategy:
        inline:
          sharding-column: user_id
          algorithm-expression: ds$->{user_id.longValue() % 2}
      sharding-algorithms:
        inline:
          type: INLINE
        snowflake:
          type: SNOWFLAKE
        tddl:
          type: TDDL
        hint:
          type: HINT
        standard:
          type: STANDARD
      props:
        sql:
          show: true
  1. 确认Sharding-JDBC的扩展点是否齐全。需要引入所有Sharding-JDBC的SPI扩展点,例如:
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-core-spi</artifactId>
    <version>4.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-transaction-spi</artifactId>
    <version>4.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-namespace</artifactId>
    <version>4.1.1</version>
</dependency>

以上是解决该错误的一些基本方案,如果还没有解决问题,可以参考Sharding-JDBC的官方文档或者在Sharding-JDBC的社区提问

springboot 项目配置sharding jdbc时候报错: No implementation class load from SPI orgapacheshardingsphereshardingspiShardingAlgorithm with type AUTO-INTERVAL的解决方案

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

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