Class ConfigProvider
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()
.-
Method Summary
Modifier and TypeMethodDescriptionstatic Config
Provide aConfig
based on allConfigSources
of the current Thread Context ClassLoader (TCCL)static Config
getConfig
(ClassLoader cl) Provide aConfig
based on allConfigSources
of the specified ClassLoader
-
Method Details
-
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
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
-