Class ConfigProvider



  • public final class ConfigProvider
    extends java.lang.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().
    • Method Detail

      • getConfig

        public static Config getConfig​()
        Provide a 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

        Returns:
        the config object for the thread context classloader
      • getConfig

        public static Config getConfig​(java.lang.ClassLoader cl)
        Provide a Config based on all ConfigSources of the specified ClassLoader

        There is exactly a single Config instance per ClassLoader

        Parameters:
        cl - the specified classloader
        Returns:
        the config for the specified classloader