Ryan-Miao opened a new issue #11318:
URL: https://github.com/apache/shardingsphere/issues/11318
## Question
I use standard table strantegy to sharding. My class implements
PreciseShardingAlgorithm, Cannot get anything from Spring context beacase of is
not the same class loader?
中文:
我自定义了分片策略,在实现的PreciseShardingAlgorithm调用Spring Context,调用静态类的静态成员变量,
都是空。我想要分片策略可以查询redis等其他介质货主分片, 但sharding加载的自定义策略不能获取其他静态对象。
```
public class SkuDbPreciseShardingAlgorithm implements
PreciseShardingAlgorithm<String> {
private static final Logger LOGGER =
LoggerFactory.getLogger(SkuDbPreciseShardingAlgorithm.class);
/**
* 分库分表
*
* @param dsNameList 可选db列表
* @param shardingValue 货主编码
* @return ds
*/
@Override
public String doSharding(Collection<String> dsNameList,
PreciseShardingValue<String> shardingValue) {
String companyCode = shardingValue.getValue();
// 这里获取的是null, 静态方法返回值null。 但我实际上在springboot启动后插入了路由
ShardingRoute route = SkuRouteRepository.getRouteMap(companyCode);
if (route != null) {
String dbName = route.getDbNo();
if (StringUtils.isNoneBlank(dbName) &&
dsNameList.contains(dbName)) {
return dbName;
}
}
LOGGER.error("没有找到配置的分片:{}", companyCode);
throw new UnsupportedOperationException();
}
}
```
--
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]