Top Description Fields Methods
org.eclipse.microprofile.config

public Interface Config

Annotations
@ProviderType
Imports
java.lang.reflect.Array, java.util.Arrays, .List, .Optional, org.eclipse.microprofile.config.spi.ConfigSource, .Converter

Resolves the property value by searching through all configured ConfigSources. If the same property is specified in multiple ConfigSources, the value in the ConfigSource with the highest ordinal will be used.

If multiple ConfigSources are specified with the same ordinal, the ConfigSource#getName() will be used for sorting.

The config objects produced via the injection model @Inject Config are guaranteed to be serializable, while the programmatically created ones are not required to be serializable.

If one or more converters are registered for a class of a requested value then the registered org.eclipse.microprofile.config.spi.Converter which has the highest @jakarta.annotation.Priority is used to convert the string value retrieved from the config sources.

Usage

For accessing the config you can use the ConfigProvider:

public void doSomething() {
    Config cfg = ConfigProvider.getConfig();
    String archiveUrl = cfg.getValue("my.project.archive.endpoint", String.class);
    Integer archivePort = cfg.getValue("my.project.archive.port", Integer.class);
}

It is also possible to inject the Config if a DI container is available:

public class MyService {
    @Inject
    private Config config;
}

See getValue(String, Class) and getOptionalValue(String, Class) for accessing a configured value.

Configured values can also be accessed via injection. See org.eclipse.microprofile.config.inject.ConfigProperty for more information.

Authors
Mark Struberg, Gerhard Petracek, Ron Smeral, Emily Jiang, Gunnar Morling

Field Summary

Modifier and TypeField and Description
public static final String
PROFILE

The value of the property specifies a single active profile.

public static final String
PROPERTY_EXPRESSIONS_ENABLED

The value of the property determines whether the property expression is enabled or disabled.

Method Summary

Modifier and TypeMethod and Description
public Iterable<ConfigSource>

Returns:

the configuration sources
getConfigSources
()

Return all of the currently registered configuration sources for this configuration.

public ConfigValue

Returns:

the resolved property value as a ConfigValue
getConfigValue
(String
The configuration property name
propertyName
)

Return the ConfigValue for the specified property name from the underlying configuration source.

public <
the conversion type
T
>
Optional<Converter<T>>

Returns:

an Optional containing the converter, or empty if no converter is available for the specified type
getConverter
(Class<T>
the type to be produced by the converter
forType
)

Return the Converter used by this instance to produce instances of the specified type from string values.

public <
The property type
T
>
Optional<T>

Returns:

The resolved property value as an Optional wrapping the requested type
getOptionalValue
(String
The configuration property name
propertyName
,
Class<T>
The type into which the resolved property value should be converted
propertyType
)

Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

public default <
The property type
T
>
Optional<List<T>>

Returns:

The resolved property values as an Optional wrapping a list of the requested type
getOptionalValues
(String
The configuration property name
propertyName
,
Class<T>
The type into which the resolved property values should be converted
propertyType
)

Return the resolved property values with the specified type for the specified property name from the underlying configuration sources.

public Iterable<String>

Returns:

the names of all configured keys of the underlying configuration
getPropertyNames
()

Returns a sequence of configuration property names.

public <
The property type
T
>
T

Returns:

the resolved property value as an instance of the requested type (not null)
getValue
(String
The configuration property name
propertyName
,
Class<T>
The type into which the resolved property value should get converted
propertyType
)

Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

public default <
The property type
T
>
List<T>

Returns:

the resolved property values as a list of instances of the requested type
getValues
(String
The configuration property name
propertyName
,
Class<T>
The type into which the resolved property values should get converted
propertyType
)

Return the resolved property values with the specified type for the specified property name from the underlying configuration sources.

public <
The type to unwrap to
T
>
T

Returns:

An instance of the given type
unwrap
(Class<T>
Class representing the type to unwrap to
type
)

Returns an instance of the specific class, to allow access to the provider specific API.

Field Detail

PROFILEback to summary
public static final String PROFILE

The value of the property specifies a single active profile.

PROPERTY_EXPRESSIONS_ENABLEDback to summary
public static final String PROPERTY_EXPRESSIONS_ENABLED

The value of the property determines whether the property expression is enabled or disabled. The value false means the property expression is disabled, while true means enabled. By default, the value is set to true.

Method Detail

getConfigSourcesback to summary
public Iterable<ConfigSource> getConfigSources()

Return all of the currently registered configuration sources for this configuration.

The returned sources will be sorted by descending ordinal value and name, which can be iterated in a thread-safe manner. The Iterable contains a fixed number of configuration sources, determined at application start time, and the config sources themselves may be static or dynamic.

Returns:Iterable<ConfigSource>

the configuration sources

getConfigValueback to summary
public ConfigValue getConfigValue(String propertyName)

Return the ConfigValue for the specified property name from the underlying configuration source. The lookup of the configuration is performed immediately, meaning that calls to ConfigValue will always yield the same results.

The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing rather than recomputing it.

A ConfigValue is always returned even if a property name cannot be found. In this case, every method in ConfigValue returns null except for ConfigValue#getName(), which includes the original property name being looked up.

Parameters
propertyName:String

The configuration property name

Returns:ConfigValue

the resolved property value as a ConfigValue

getConverterback to summary
public <T> Optional<Converter<T>> getConverter(Class<T> forType)

Return the Converter used by this instance to produce instances of the specified type from string values.

Parameters
<T>
the conversion type
forType:Class<T>

the type to be produced by the converter

Returns:Optional<Converter<T>>

an Optional containing the converter, or empty if no converter is available for the specified type

getOptionalValueback to summary
public <T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType)

Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing rather than recomputing it.

If this method is used very often then consider to locally store the configured value.

Parameters
<T>
The property type
propertyName:String

The configuration property name

propertyType:Class<T>

The type into which the resolved property value should be converted

Returns:Optional<T>

The resolved property value as an Optional wrapping the requested type

Exceptions
IllegalArgumentException:
if the property cannot be converted to the specified type
getOptionalValuesback to summary
public default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> propertyType)

Return the resolved property values with the specified type for the specified property name from the underlying configuration sources.

The configuration values are not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned values are intended to be frequently used, callers should consider storing rather than recomputing them.

Parameters
<T>
The property type
propertyName:String

The configuration property name

propertyType:Class<T>

The type into which the resolved property values should be converted

Returns:Optional<List<T>>

The resolved property values as an Optional wrapping a list of the requested type

Exceptions
IllegalArgumentException:
if the property cannot be converted to the specified type
getPropertyNamesback to summary
public Iterable<String> getPropertyNames()

Returns a sequence of configuration property names. The order of the returned property names is unspecified.

The returned property names are unique; that is, if a name is returned once by a given iteration, it will not be returned again during that same iteration.

There is no guarantee about the completeness or currency of the names returned, nor is there any guarantee that a name that is returned by the iterator will resolve to a non-empty value or be found in any configuration source associated with the configuration; for example, it is allowed for this method to return an empty set always. However, the implementation should return a set of names that is useful to a user that wishes to browse the configuration.

It is implementation-defined whether the returned names reflect a point-in-time "snapshot" of names, or an aggregation of multiple point-in-time "snapshots", or a more dynamic view of the available property names. Implementations are not required to return the same sequence of names on each iteration; however, the produced Iterator must adhere to the contract of that class, and must not return any more elements once its hasNext() method returns false.

The returned instance is thread safe and may be iterated concurrently. The individual iterators are not thread-safe.

Returns:Iterable<String>

the names of all configured keys of the underlying configuration

getValueback to summary
public <T> T getValue(String propertyName, Class<T> propertyType)

Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing rather than recomputing it.

The result of this method is identical to the result of calling getOptionalValue(propertyName, propertyType).get(). In particular, If the given property name or the value element of this property does not exist, the java.util.NoSuchElementException is thrown. This method never returns null.

Parameters
<T>
The property type
propertyName:String

The configuration property name

propertyType:Class<T>

The type into which the resolved property value should get converted

Returns:T

the resolved property value as an instance of the requested type (not null)

Exceptions
IllegalArgumentException:
if the property cannot be converted to the specified type
NoSuchElementException:
if the property is not defined or is defined as an empty string or the converter returns null
getValuesback to summary
public default <T> List<T> getValues(String propertyName, Class<T> propertyType)

Return the resolved property values with the specified type for the specified property name from the underlying configuration sources.

The configuration values are not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned values are intended to be frequently used, callers should consider storing rather than recomputing them.

Parameters
<T>
The property type
propertyName:String

The configuration property name

propertyType:Class<T>

The type into which the resolved property values should get converted

Returns:List<T>

the resolved property values as a list of instances of the requested type

Exceptions
IllegalArgumentException:
if the property values cannot be converted to the specified type
NoSuchElementException:
if the property isn't present in the configuration or is defined as an empty string or the converter returns null
unwrapback to summary
public <T> T unwrap(Class<T> type)

Returns an instance of the specific class, to allow access to the provider specific API.

If the MP Config provider implementation does not support the specified class, a IllegalArgumentException is thrown.

Unwrapping to the provider specific API may lead to non-portable behaviour.

Parameters
<T>
The type to unwrap to
type:Class<T>

Class representing the type to unwrap to

Returns:T

An instance of the given type

Exceptions
IllegalArgumentException:
If the current provider does not support unwrapping to the given type