Class ConfigProvider
- java.lang.Object
-
- org.eclipse.microprofile.config.ConfigProvider
-
public final class ConfigProvider extends java.lang.Object
This is the central class to access a
Config
. AConfig
provides access to application Configuration. That might be auto-discoveredConfig
or even manually created one.The default usage is to use
getConfig()
to automatically pick up the 'Configuration' for the Thread Context ClassLoader (SeeThread.getContextClassLoader()
).A 'Configuration' consists of the information collected from the registered
ConfigSources
. TheseConfigSources
get sorted according to their ordinal defined viaConfigSource.getOrdinal()
. Thus it is possible to overwrite configuration by providing in a ConfigSource with higher importance from outside.It is also possible to register custom
ConfigSources
to flexibly extend the configuration mechanism. An example would be to pick up configuration values from a database table. Example usage:String restUrl = ConfigProvider.getConfig().getValue("myproject.some.remote.service.url", String.class); Integer port = ConfigProvider.getConfig().getValue("myproject.some.remote.service.port", Integer.class);
For more advanced use cases like e.g. registering a manually createdConfig
please seeConfigProviderResolver.registerConfig(Config, ClassLoader)
andConfigProviderResolver.getBuilder()
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Config
getConfig()
Provide aConfig
based on allConfigSources
of the current Thread Context ClassLoader (TCCL)static Config
getConfig(java.lang.ClassLoader cl)
Provide aConfig
based on allConfigSources
of the specified ClassLoader
-
-
-
Method Detail
-
getConfig
public static Config getConfig()
Provide aConfig
based on allConfigSources
of the current Thread Context ClassLoader (TCCL)The
Config
will be stored for future retrieval.There is exactly a single Config instance per ClassLoader
- Returns:
- the config object for the thread context classloader
-
getConfig
public static Config getConfig(java.lang.ClassLoader cl)
Provide aConfig
based on allConfigSources
of the specified ClassLoaderThere is exactly a single Config instance per ClassLoader
- Parameters:
cl
- the specified classloader- Returns:
- the config for the specified classloader
-
-