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 :
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);
}
sources:
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
io.helidon.config.Config
and org.eclipse.microprofile.config.Config
are different APIs.
Helidon provides an implementation of MicroProfile Config with the following Maven dependency io.helidon.config:helidon-config-mp
.
You can create an instance like this:
org.eclipse.microprofile.config.ConfigProvider.getConfig()
Helidon also provides a few SPIs along its implementation of MicroProfile Config, one of which is io.helidon.config.mp.spi.MpMetaConfigProvider
.
When creating an instance of MicroProfile using the above, implementations of MpMetaConfigProvider
are used.
Helidon also provides a bridge to create instances of MicroProfile Config backed by io.helidon.config.Config
.
// create an instance of "Helidon Config"
io.helidon.config.Config config0 = io.helidon.config.Config.create();
// create an instance of "MicroProfile Config" backed by "Helidon Config"
org.eclipse.microprofile.config.Config config =
ConfigProviderResolver.instance()
.getBuilder()
.withSources(MpConfigSources.create(config0))
.build();
The code above will NOT use implementations of MpMetaConfigProvider
.
In order for your code to pickup your implementation of MpMetaConfigProvider
you can either:
Server.Builder(org.eclipse.microprofile.config.Config)
instead of Server.Builder(io.helidon.config.Config)
with an instance created using ConfigProvider.getConfig()