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 .

--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]