Class MetaConfig


  • public final class MetaConfig
    extends Object
    Meta configuration.

    Configuration allows configuring itself using meta configuration. Config looks for meta-config.* files in the current directory and on the classpath, where the * is one of the supported media type suffixes (such as yaml when helidon-config-yaml module is on the classpath).

    Meta configuration can define which config sources to load, including possible retry policy, polling strategy and change watchers.

    Example of a YAML meta configuration file:

     sources:
       - type: "environment-variables"
       - type: "system-properties"
       - type: "file"
         properties:
           path: "conf/dev.yaml"
           optional: true
       - type: "file"
         properties:
           path: "conf/config.yaml"
           optional: true
       - type: "classpath"
         properties:
           resource: "default.yaml"
     
    This configuration would load the following config sources (in the order specified):
    • Environment variables config source
    • System properties config source
    • File config source from file conf/dev.yaml that is optional
    • File config source from file conf/config.yaml that is optional
    • Classpath resource config source for resource default.yaml that is mandatory
    • Method Detail

      • config

        public static Config config()
        Create configuration from meta configuration (files or classpath resources), or create a default config instance if meta configuration is not present.
        Returns:
        a config instance
      • config

        public static Config config​(Config metaConfig)
        Create configuration from provided meta configuration.
        Parameters:
        metaConfig - meta configuration
        Returns:
        a new config instance built from meta configuration
      • metaConfig

        public static Optional<Config> metaConfig()
        Find meta configuration (files or classpath resources) and create a meta configuration instance from it.
        Returns:
        meta configuration if present, or empty
      • pollingStrategy

        public static PollingStrategy pollingStrategy​(Config metaConfig)
        Load a polling strategy based on its meta configuration.
        Parameters:
        metaConfig - meta configuration of a polling strategy
        Returns:
        a polling strategy instance
      • changeWatcher

        public static ChangeWatcher<?> changeWatcher​(Config metaConfig)
        Load a change watcher based on its meta configuration.
        Parameters:
        metaConfig - meta configuration of a change watcher
        Returns:
        a change watcher instance
      • retryPolicy

        public static RetryPolicy retryPolicy​(Config metaConfig)
        Load a retry policy based on its meta configuration.
        Parameters:
        metaConfig - meta configuration of retry policy
        Returns:
        retry policy instance
      • configSource

        public static List<ConfigSource> configSource​(Config sourceMetaConfig)
        Load a config source (or config sources) based on its meta configuration. The metaConfig must contain a key type that defines the type of the source to be found via providers, and a key properties with configuration of the config sources
        Parameters:
        sourceMetaConfig - meta configuration of a config source
        Returns:
        config source instance
        See Also:
        Config.Builder.config(Config)