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:
- System properties (ordinal=400)
- Environment properties (ordinal=300)
- /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.ConfigSourcewhich 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
-
Method Summary
Modifier and TypeMethodDescriptiongetName()
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 sourceGets all property names known to this config source, without evaluating the values.Return the value for the specified property in this config source.
-
Field Details
-
CONFIG_ORDINAL
- See Also:
-
DEFAULT_ORDINAL
static final int DEFAULT_ORDINAL- See Also:
-
-
Method Details
-
getProperties
Return the properties in this config source- Returns:
- the map containing the properties in this config source
-
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 ofgetProperties()
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:- System properties (ordinal=400)
- 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"
):- Exact match (i.e.
"com.ACME.size"
) - Replace the character that is neither alphanumeric nor '_' with '_' (i.e.
"com_ACME_size"
) - 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.
- Exact match (i.e.
- /META-INF/microprofile-config.properties (default ordinal=100)
- Returns:
- the ordinal value
-
getValue
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'
-