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 2021/07/13 11:17:47 UTC
[GitHub] [shardingsphere] Ryan-Miao opened a new issue #11318: Customize ShardingAlgorithm cannot get Bean from Spring
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] RaigorJiang commented on issue #11318: Customize ShardingAlgorithm cannot get Bean from Spring
Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #11318:
URL: https://github.com/apache/shardingsphere/issues/11318#issuecomment-924734076
Since this issue has been inactive for more than 30 days, we will close it.
If you still have related questions, please submit a new issue, thank you.
--
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] RaigorJiang closed issue #11318: Customize ShardingAlgorithm cannot get Bean from Spring
Posted by GitBox <gi...@apache.org>.
RaigorJiang closed issue #11318:
URL: https://github.com/apache/shardingsphere/issues/11318
--
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] strongduanmu commented on issue #11318: Customize ShardingAlgorithm cannot get Bean from Spring
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #11318:
URL: https://github.com/apache/shardingsphere/issues/11318#issuecomment-879498669
@Ryan-Miao You can try to use the Hint for routing. For more information, please refer this [doc](https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/sharding/hint/).
--
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