apache / servicecomb-java-chassis

ServiceComb Java Chassis is a Software Development Kit (SDK) for rapid development of microservices in Java, providing service registration, service discovery, dynamic routing, and service management features
Apache License 2.0
1.91k stars 814 forks source link

DynamicPropertiesSource接口定义的不太好 #4560

Closed yinhaox closed 1 month ago

yinhaox commented 1 month ago

我想使用org.apache.commons.configuration2作为动态配置源

为此我写了个简单的demo:

public class MyDynamicPropertiesSource implements DynamicPropertiesSource {
    @Override
    public MapPropertySource create(Environment environment) {
        Parameters params = new Parameters();
        File propertiesFile = new File("config.properties");
        ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder =
                new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                        .configure(params.fileBased().setFile(propertiesFile));
        PeriodicReloadingTrigger trigger = new PeriodicReloadingTrigger(builder.getReloadingController(), null, 15, TimeUnit.SECONDS);
        trigger.start();

        try {
            return new ConfigurationPropertySource("local", builder.getConfiguration());
        } catch (ConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int getOrder() {
        return 0;
    }
}

ConfigurationPropertySource是configuration2提供的Spring PropertySources

但是DynamicPropertiesSource接口只支持返回MapPropertySource。

是否可以修改DynamicPropertiesSource接口里返回值的定义为PropertySource<?>