关于升级到shardingsphere5.3之后,原sping BeanPostProcessor的一些遗留问题

当前版本 5.2.1 下面这一段代码的目的是为了不在yaml配置文件里面配置shardindjdbc的分片表配置。从而采用编码的方式去更改配置。当前的需求是不分表 只是分库 而且是针对整个模块的业务表进行这样操作。

升级到5.3.0之后 由于采用了org.apache.shardingsphere.driver.ShardingSphereDriver 的方式。无法继续用这种配置来实现。咨询一下大家有什么好的方法来实现吗? 因为数据表涉及到数十张,在yaml里面一个一个配置很麻烦。

spring.shardingsphere.rules.sharding.sharding-algorithms.sharding_algorithm_hit.type=sharding_algorithm_hit
@Component
public class ShardingSphereProcessor implements BeanPostProcessor, PriorityOrdered {
   ........此处省略一些代码
  //需要分库的表名
  `List<String>`  shardingTables=Lists.newArrayList();
  
   @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof YamlReadwriteSplittingRuleSpringBootConfiguration){
            //System.out.println(beanName);
        }
        if (bean instanceof YamlShardingRuleSpringBootConfiguration) {
            YamlShardingRuleSpringBootConfiguration properties = (YamlShardingRuleSpringBootConfiguration) bean;
            Map<String, YamlTableRuleConfiguration> tables = properties.getSharding().getTables();
           //在这里统一设置分片规则
            for (`String` tableName : shardingTables) {
                YamlTableRuleConfiguration configuration = new YamlTableRuleConfiguration();
                configuration.setActualDataNodes("ms$->{1..3}." + tableName);
                tables.put(tableName,configuration);
            }
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }
 
}
京ICP备2021015875号