Class ConfigProvider
- java.lang.Object
-
- org.eclipse.microprofile.config.ConfigProvider
-
public final class ConfigProvider extends Object
This is the central class to access aConfig
.A
Config
provides access to the application's configuration. It may have been automatically discovered, or manually created and registered.The default usage is to use
getConfig()
to automatically pick up the configuration for the current thread's context class loader.A configuration consists of information collected from the registered configuration sources, combined with the set of registered converters. The configuration sources get sorted according to their ordinal value. Thus it is possible to override a lower-priority configuration source with a higher-priority one.
It is also possible to register custom configuration sources to flexibly extend the configuration mechanism. For example, a configuration source could be provided which reads configuration values from a database table.
Example:
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 (e.g. registering a manually created
Config
instance), please seeConfigProviderResolver.registerConfig(Config, ClassLoader)
andConfigProviderResolver.getBuilder()
.- Author:
- Mark Struberg, Romain Manni-Bucau, Emily Jiang, Viktor Klang
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Config
getConfig()
Get the configuration corresponding to the current application, as defined by the calling thread's context class loader.static Config
getConfig(ClassLoader cl)
Get the configuration for the application corresponding to the given class loader instance.
-
-
-
Method Detail
-
getConfig
public static Config getConfig()
Get the configuration corresponding to the current application, as defined by the calling thread's context class loader.The
Config
instance will be created and registered to the context class loader if no such configuration is already created and registered.Each class loader corresponds to exactly one configuration.
- Returns:
- the configuration instance for the thread context class loader
-
getConfig
public static Config getConfig(ClassLoader cl)
Get the configuration for the application corresponding to the given class loader instance.The
Config
instance will be created and registered to the given class loader if no such configuration is already created and registered.Each class loader corresponds to exactly one configuration.
- Parameters:
cl
- the Classloader used to register the configuration instance- Returns:
- the configuration instance for the given class loader
-
-