I have made the changes as suggested in the doc : https://helidon.io/docs/v2/#/mp/config/02_MP_config_sources But it is not able to identify the new config source and gives the following error : Config source of type test-config-provider is not supported`
Here are the changes that I have done to add the new Custom Config Source :
- Created a MyConfigProvider class which implements MpMetaConfigProvider
- Created class MyConfigSource which implements ConfigSource
- MyConfigProvider::create() and supportedTypes()
public static final String TYPE = "test-config-provider";
@Override
public List<? extends ConfigSource> create(String s, Config config, String s1) {
Map<String, String> result = new HashMap<String, String>();
ConfigSource configSource = new MyConfigSource(result);
return Collections.singletonList(configSource);
}
@Override
public Set<String> supportedTypes() {
return Set.of(TYPE);
}
- Inside resources/META-INF, added services/io.helidon.config.mp.spi.MpMetaConfigProvider file. In the file added the file package path for MyConfigProvider i.e <package_name>.MyConfigProvider
- File : 'mp-meta-config.yaml' contents add-discovered-sources: true add-discovered-converters: false add-default-sources: true
sources:
- type: "environment-variables"
- type: "system-properties"
- type: "test-config-provider"
- In my main() function we are creating the Config instance and passing it to the Server builder()
public class Main {
private static final String DEFAULT_CONFIG_FILE = "mp-meta-config.yaml";
public static void main(final String\[\] args) {
Config config = buildHelidonConfig();
Server server = startServer1(config);
//Server server = startServer2();
}
private static Config buildHelidonConfig() {
return MetaConfig.config(Config.create(getSources()));
}private static Supplier<? extends ConfigSource>[] getSources() {
return new Supplier[] {
classpath(DEFAULT_CONFIG_FILE).build()
};
}
public static Server startServer1(Config config) {
return Server
.builder()
.config(config)
.build()
.start();
}
}
But it is not able to identify the new config source and gives the following error :
Config source of type test-config-provider is not supported