You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/02/25 09:54:18 UTC

[GitHub] [shardingsphere] wsg96321 opened a new issue #15636: Exception with No implementation class load from SPI

wsg96321 opened a new issue #15636:
URL: https://github.com/apache/shardingsphere/issues/15636


   version : v5.1.0  sharding-jdbc
   
   hello , below is the code of my own : 
   ```
   public final class DatabaseHintShardingAlgorithm implements HintShardingAlgorithm<String> {
   
       @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, HintShardingValue<String> shardingValue) {
           Collection<String> result = new ArrayList<>();
           for (String each : availableTargetNames) {
               for (String value : shardingValue.getValues()) {
                   String[] values = value.split(",");
                   for (String s : values) {
                       if (each.endsWith("_" + s)) {
                           result.add(each);
                       }
                   }
               }
           }
           return result;
       }
   
       @Override
       public void init() {
   
       }
   
       @Override
       public String getType() {
           return "COMMON_SHARD";
       }
   }
   ```
   
   But when I use it in my test code it report ERROR:
   ```
   File ymlfile = new File(HintAlgorithmTest.class.getResource("/META-INF/config-xx.yaml").getFile());
   dataSource = YamlShardingSphereDataSourceFactory.createDataSource(ymlfile);
   ```
   
   
   ```
   Exception in thread "main" org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException: No implementation class load from SPI `org.apache.shardingsphere.sharding.spi.ShardingAlgorithm` with type `COMMON_SHARD`.
   	at org.apache.shardingsphere.spi.typed.TypedSPIRegistry.getRegisteredService(TypedSPIRegistry.java:76)
   	at org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory.createAlgorithm(ShardingSphereAlgorithmFactory.java:41)
   	at org.apache.shardingsphere.sharding.rule.ShardingRule.lambda$new$0(ShardingRule.java:109)
   	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
   	at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:109)
   	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:41)
   	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:35)
   	at org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder.buildRules(SchemaRulesBuilder.java:63)
   	at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.getSchemaRules(MetaDataContextsBuilder.java:85)
   	at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.addSchema(MetaDataContextsBuilder.java:77)
   	at org.apache.shardingsphere.mode.manager.memory.MemoryContextManagerBuilder.build(MemoryContextManagerBuilder.java:47)
   	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:81)
   	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
   	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:77)
   	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:132)
   	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:61)
   ```
   below is my config : 
   ```
   schemaName: test
   
   dataSources:
     ds_1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.jdbc.Driver
       url: jdbc:mysql://10.0.0.1:3306/player_90001
       username: test
       password: test
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 10
     ds_2:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.jdbc.Driver
       url: jdbc:mysql://10.0.0.2:3306/player_90002
       username: test
       password: test
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 10
   
   rules:
   - !SHARDING
     tables:
       hero:
         actualDataNodes: ds_${1..2}.hero
     bindingTables:
       - hero
   
     defaultDatabaseStrategy:
       hint:
         shardingAlgorithmName: hint-common
     defaultTableStrategy:
       none:
   
     shardingAlgorithms:
       hint-common:
         type: COMMON_SHARD
   
   props:
     sql-show: true
   ```
   
   I found it is seems to this issues : [(https://github.com/apache/shardingsphere/issues/12703)](https://github.com/apache/shardingsphere/issues/12703)
   Then I have read the code with [https://github.com/apache/shardingsphere/blob/5.1.0/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/.../shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java](https://github.com/apache/shardingsphere/blob/5.1.0/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java), but find no idea to deal with this problem. 
   
   PS: this is my structure with project though I don't know why need to use directory `META-INF` and `services`, and it is unuse . 
   
   ![image](https://user-images.githubusercontent.com/8844009/155693510-2abaac26-309e-4383-8eb3-bc445e84fa27.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] wsg96321 closed issue #15636: Exception with No implementation class load from SPI

Posted by GitBox <gi...@apache.org>.
wsg96321 closed issue #15636:
URL: https://github.com/apache/shardingsphere/issues/15636


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] wsg96321 commented on issue #15636: Exception with No implementation class load from SPI

Posted by GitBox <gi...@apache.org>.
wsg96321 commented on issue #15636:
URL: https://github.com/apache/shardingsphere/issues/15636#issuecomment-1053810649


   Thanks a lot . I think I have resolve this problem . It's my mistake for the wrong file name in services. The file name in /META-INF/services must be `org.apache.shardingsphere.sharding.spi.ShardingAlgorithm`. This is my test project , hope to it can help others.  
   [https://github.com/wsg96321/sharding-project.git](https://github.com/wsg96321/sharding-project.git)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] zjcnb commented on issue #15636: Exception with No implementation class load from SPI

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #15636:
URL: https://github.com/apache/shardingsphere/issues/15636#issuecomment-1050712131


   @wsg96321 Hi, Can your provider your project ? Maybe your META-INF/services structure has problem. https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/sharding/raw/jdbc/ShardingHintRawExample.java
    


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org