No implementation class load from SPI
Which version of ShardingSphere did you use?
implementation ('org.apache.shardingsphere:shardingsphere-jdbc:5.5.1') spring boot 3.3.3
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere JDBC
Expected behavior
submeter
Actual behavior
Starting a service without recompiling may sometimes result in this exception, but restarting it multiple times still works normally
[2025-03-04 14:27:02] content: Caused by: org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException: SPI-00001: No implementation class load from SPI 'org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade' with type 'null'.
+1 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader.lambda$getService$1(TypedSPILoader.java:110)
+2 [2025-03-04 14:27:02] content: at java.base/java.util.Optional.orElseThrow(Optional.java:403)
+3 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader.lambda$getService$2(TypedSPILoader.java:110)
+4 [2025-03-04 14:27:02] content: at java.base/java.util.Optional.orElseGet(Optional.java:364)
+5 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader.getService(TypedSPILoader.java:110)
+6 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader.getService(TypedSPILoader.java:97)
+7 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader.lambda$getService$0(DatabaseTypedSPILoader.java:83)
+8 [2025-03-04 14:27:02] content: at java.base/java.util.Optional.orElseGet(Optional.java:364)
+9 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader.getService(DatabaseTypedSPILoader.java:83)
+10 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.twoPhaseParse(SQLParserExecutor.java:57)
+11 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.parse(SQLParserExecutor.java:49)
+12 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.sql.parser.api.SQLParserEngine.parse(SQLParserEngine.java:53)
+13 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.parser.sql.SQLStatementParserExecutor.parse(SQLStatementParserExecutor.java:47)
+14 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader.load(SQLStatementCacheLoader.java:42)
+15 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader.load(SQLStatementCacheLoader.java:31)
+16 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.LocalLoadingCache.lambda$newMappingFunction$3(LocalLoadingCache.java:183)
+17 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2688)
+18 [2025-03-04 14:27:02] content: at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1916)
+19 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2686)
+20 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2669)
+21 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:112)
+22 [2025-03-04 14:27:02] content: at com.github.benmanes.caffeine.cache.LocalLoadingCache.get(LocalLoadingCache.java:58)
+23 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine.parse(SQLStatementParserEngine.java:57)
+24 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine.parse(ShardingSphereSQLParserEngine.java:53)
+25 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.parseSQL(ShardingSpherePreparedStatement.java:163)
+26
[2025-03-04 14:27:02]
content: at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.
+27
[2025-03-04 14:27:02]
content: at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.
+28 [2025-03-04 14:27:02] content: at org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection.prepareStatement(ShardingSphereConnection.java:111)
+29 [2025-03-04 14:27:02] content: at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:328)
+30 [2025-03-04 14:27:02] content: at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java)
+31 [2025-03-04 14:27:02] content: at com.rjhy.base.config.mysql.LogConnection.prepareStatement(LogConnection.java:36)
Example codes for reproduce this issue (such as a github link).
configuration file
dataSources: content-algorithm: dataSourceClassName: com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.cj.jdbc.Driver jdbcUrl: jdbc:mysql://xxxxxx:3306/rjhy_content_algorithm?characterEncoding=utf8&serverTimezone=GMT%2b8&connectTimeout=5000&socketTimeout=30000 username: xxxxx password: xxxxxx
rules:
- !SINGLE
tables:
- "."
- !SHARDING
tables: # 数据分片规则配置
t_user_concern_push_content: # 逻辑表名称
actualDataNodes: content-algorithm.t_user_concern_push_content_${0..1}
tableStrategy: # 分表策略,同分库策略
standard:
shardingColumn: username
shardingAlgorithmName: username_hash_mod
keyGenerateStrategy: # 分布式序列策略
column: id
keyGeneratorName: customKeyGenerator
分片算法配置
shardingAlgorithms: username_hash_mod: type: CUSTOM_SHARDING_STRATEGY props: sharding-count: '2'分布式序列算法配置
keyGenerators: customKeyGenerator: type: CUSTOM_KEY_GENERATOR props: sql-show: false
My version is also Spring 3 and ShardingSphere 5.5.1. When using multiple sharding strategies and loading algorithm implementation classes via SPI, I encountered the same issue. I believe this is caused by version incompatibility.
Additionally, I found that the defaultTableStrategy configuration did not take effect, and I had to manually specify a strategy for each table that does not require sharding.
`dataSources: ds0: dataSourceClassName: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://xxxxxxxxxxxx:3306/message_dispatch?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT username: xxxxxxxxxx password: xxxxxxxx props: initialSize: 5 maxActive: 20 minIdle: 5 maxWait: 60000
rules:
-
!SHARDING defaultTableStrategy: none:
defaultDatabaseStrategy: none:
tables: in_app: actualDataNodes: ds0.in_app in_app_access: actualDataNodes: ds0.in_app_access in_app_access_config: actualDataNodes: ds0.in_app_access_config in_app_group: actualDataNodes: ds0.in_app_group in_app_group_user: actualDataNodes: ds0.in_app_group_user in_app_template: actualDataNodes: ds0.in_app_template in_app_text: actualDataNodes: ds0.in_app_text in_app_record_old: actualDataNodes: ds0.in_app_record_old in_app_record: actualDataNodes: ds0.in_app_record_${0..7} tableStrategy: standard: shardingColumn: user_no,company_no shardingAlgorithmName: consistent-hash-algoshardingAlgorithms: consistent-hash-algo: type: COMPLEX props: logical-table-name: in_app_record algorithm-expression: com.msl.message.in.app.sharding.ConsistentHashShardingAlgorithm sharding-count: 8
props: sql-show: true
`
Hi ! I meet the same issue, when running springboot application in built jar. Actually the SPI implementations in shardingsphere-jdbc are loaded correctly. While SPI implementations in other deeper dependence jars are not loaded. And those deeper dependence jars are also in the group of org.apache.shardingsphere. Do you have any idea how to resolve it?
遇到同样问题。No implementation class load from SPI org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade with type MySQL.
使用gc+load日志发现,shardingsphere-parser-sql-mysql这个jar都没有load,这个jar已经打包到了BOOT-INF/lib/
For English only
I also encountered the same problem. How can this problem be solved? Help needed ~ ~