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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    The name of the config might be used for logging or analysis of configured values.
    default int
    Return the ordinal for this config source.
    Return the properties in this config source
    default Set<String>
    Gets all property names known to this config source, without evaluating the values.
    getValue(String propertyName)
    Return the value for the specified property in this config source.
  • Field Details

  • Method Details

    • getProperties

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

      default Set<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 (default ordinal=400)
      2. Environment properties (default ordinal=300)
      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

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

      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'