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. which has the highest @jakarta.annotation.Priority is
used to convert the string value retrieved from the config sources.
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. for more information.
| Modifier and Type | Field 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. |
| Modifier and Type | Method and Description |
|---|---|
| public Iterable | Returns: the configuration sourcesReturn all of the currently registered configuration sources for this configuration. |
| public ConfigValue | Returns: the resolved property value as aConfigValueThe configuration property name propertyName)Return the |
| public < the conversion type T> Optional | Returns: anOptional containing the converter, or empty if no converter is available for the specified
typethe type to be produced by the converter forType)Return the |
| public < The property type T> Optional | Returns: The resolved property value as anOptional wrapping the requested typeThe 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 | Returns: The resolved property values as anOptional wrapping a list of the requested typeThe 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 | Returns: the names of all configured keys of the underlying configurationReturns a sequence of configuration property names. |
| public < The property type T> T | Returns: the resolved property value as an instance of the requested type (notnull)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 | Returns: the resolved property values as a list of instances of the requested typeThe 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 |
| PROFILE | back to summary |
|---|---|
| public static final String PROFILE The value of the property specifies a single active profile. | |
| PROPERTY_EXPRESSIONS_ENABLED | back 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
| |
| getConfigSources | back to summary |
|---|---|
| public Iterable 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
| |
| getConfigValue | back to summary |
|---|---|
| public ConfigValue getConfigValue(String propertyName) Return the 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
| |
| getConverter | back to summary |
|---|---|
| public <T> Optional Return the | |
| getOptionalValue | back to summary |
|---|---|
| public <T> Optional 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.
| |
| getOptionalValues | back to summary |
|---|---|
| public default <T> Optional 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.
| |
| getPropertyNames | back to summary |
|---|---|
| public Iterable 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
The returned instance is thread safe and may be iterated concurrently. The individual iterators are not thread-safe. | |
| getValue | back 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
| |
| getValues | back to summary |
|---|---|
| public default <T> List 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.
| |
| unwrap | back 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 Unwrapping to the provider specific API may lead to non-portable behaviour.
| |