Class ConfigProvider


  • public final class ConfigProvider
    extends java.lang.Object

    This is the central class to access a 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 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 (e.g. registering a manually created Config instance), please see ConfigProviderResolver.registerConfig(Config, ClassLoader) and ConfigProviderResolver.getBuilder().
    • 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​(java.lang.ClassLoader cl)
      Get the configuration for the application corresponding to the given class loader instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(java.lang.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.

        Returns:
        the configuration instance for the given class loader