public final class ConfigProvider
extends java.lang.Object
Config
.
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 see
ConfigProviderResolver.registerConfig(Config, ClassLoader)
and ConfigProviderResolver.getBuilder()
.
Modifier and Type | Method and 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(java.lang.ClassLoader cl)
Get the configuration for the application corresponding to the given class loader instance.
|
public static Config getConfig()
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.
public static Config getConfig(java.lang.ClassLoader cl)
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.
cl
- the Classloader used to register the configuration instance