Interface ConfigSource



  • public interface ConfigSource

    Implement this interfaces to provide a ConfigSource. A ConfigSource provides configuration values from a specific place, like JNDI configuration, a properties file, etc. A ConfigSource is always read-only, any potential updates of the configured values must be handled directly inside each ConfigSource.

    The default config sources always available by default are:

    1. System properties (ordinal=400)
    2. Environment properties (ordinal=300)
    3. /META-INF/microprofile-config.properties (ordinal=100)

    Custom ConfigSource will get picked up via the ServiceLoader mechanism and and can be registered by providing a file

         META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
     
    which contains the fully qualified ConfigSource implementation class name as content.

    Adding a dynamic amount of custom config sources can be done programmatically via ConfigSourceProvider.

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.lang.String getName​()
      The name of the config might be used for logging or analysis of configured values.
      default int getOrdinal​()
      Return the ordinal for this config source.
      java.util.Map<java.lang.String,java.lang.String> getProperties​()
      Return the properties in this config source
      default java.util.Set<java.lang.String> getPropertyNames​()
      Gets all property names known to this config source, without evaluating the values.
      java.lang.String getValue​(java.lang.String propertyName)
      Return the value for the specified property in this config source.
    • Method Detail

      • getProperties

        java.util.Map<java.lang.String,java.lang.String> getProperties​()
        Return the properties in this config source
        Returns:
        the map containing the properties in this config source
      • getPropertyNames

        default java.util.Set<java.lang.String> getPropertyNames​()
        Gets all property names known to this config source, without evaluating the values. For backwards compatibility, there is a default implementation that just returns the keys of getProperties() slower ConfigSource implementations should replace this with a more performant implementation
        Returns:
        the set of property keys that are known to this ConfigSource
      • getOrdinal

        default int getOrdinal​()
        Return the ordinal for this config source. If a property is specified in multiple config sources, the value in the config source with the highest ordinal takes precedence. For the config sources with the same ordinal value, the config source names will be used for sorting according to string sorting criteria. Note that this property only gets evaluated during ConfigSource discovery. The default ordinals for the default config sources:
        1. System properties (ordinal=400)
        2. Environment properties (ordinal=300)

          Some operating systems allow only alphabetic characters or an underscore(_), in environment variables. Other characters such as ., /, etc may be disallowed. In order to set a value for a config property that has a name containing such disallowed characters from an environment variable, the following rules are used. This ConfigSource searches for potentially 3 environment variables with a given property name (e.g. "com.ACME.size"):

          1. Exact match (i.e. "com.ACME.size")
          2. Replace the character that is neither alphanumeric nor '_' with '_' (i.e. "com_ACME_size")
          3. Replace the character that is neither alphanumeric nor '_' with '_' and convert to upper case (i.e. "COM_ACME_SIZE")

          The first environment variable that is found is returned by this ConfigSource.

        3. /META-INF/microprofile-config.properties (default ordinal=100)
        Any ConfigSource part of an application will typically use an ordinal between 0 and 200. ConfigSource provided by the container or 'environment' typically use an ordinal higher than 200. A framework which intends have values overwritten by the application will use ordinals between 0 and 100. The property "config_ordinal" can be specified to override the default value.
        Returns:
        the ordinal value
      • getValue

        java.lang.String getValue​(java.lang.String propertyName)
        Return the value for the specified property in this config source.
        Parameters:
        propertyName - the property name
        Returns:
        the property value
      • getName

        java.lang.String getName​()
        The name of the config might be used for logging or analysis of configured values.
        Returns:
        the 'name' of the configuration source, e.g. 'property-file mylocation/myproperty.properties'