public final class ConfigProvider extends Object
This is the central class to access a Config
.
A Config
provides access to application Configuration.
That might be auto-discovered Config
or even manually created one.
The default usage is to use getConfig()
to automatically pick up the
'Configuration' for the Thread Context ClassLoader (See
Thread.getContextClassLoader()
).
A 'Configuration' consists of the information collected from the registered ConfigSources
.
These ConfigSources
get sorted according to
their ordinal defined via ConfigSource.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 created
Config
please see
ConfigProviderResolver.registerConfig(Config, ClassLoader)
and ConfigProviderResolver.getBuilder()
.Modifier and Type | Method and Description |
---|---|
static Config |
getConfig()
Provide a
Config based on all ConfigSources of the
current Thread Context ClassLoader (TCCL) |
static Config |
getConfig(ClassLoader cl)
Provide a
Config based on all ConfigSources of the
specified ClassLoader |
public static Config getConfig()
Config
based on all ConfigSources
of the
current Thread Context ClassLoader (TCCL)
The Config
will be stored for future retrieval.
There is exactly a single Config instance per ClassLoader
public static Config getConfig(ClassLoader cl)
Config
based on all ConfigSources
of the
specified ClassLoader
There is exactly a single Config instance per ClassLoader
cl
- the specified classloaderCopyright © 2019 JBoss by Red Hat. All rights reserved.