@ProviderType public interface Config
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 Converter
which has the highest @javax.annotation.Priority
is used to convert the string value retrieved from the config sources.
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 ConfigProperty
for more information.
Modifier and Type | Method and Description |
---|---|
Iterable<ConfigSource> |
getConfigSources()
Return all of the currently registered configuration sources for this configuration.
|
<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.
|
Iterable<String> |
getPropertyNames()
Return all property names returned by any of the underlying configuration sources.
|
<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.
|
<T> T getValue(String propertyName, Class<T> propertyType)
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.
T
- The property typepropertyName
- The configuration property namepropertyType
- The type into which the resolved property value should get convertedIllegalArgumentException
- if the property cannot be converted to the specified typeNoSuchElementException
- if the property isn't present in the configuration<T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType)
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.
T
- The property typepropertyName
- The configuration property namepropertyType
- The type into which the resolved property value should be convertedOptional
wrapping the requested typeIllegalArgumentException
- if the property cannot be converted to the specified typeIterable<String> getPropertyNames()
Iterable<ConfigSource> getConfigSources()
Copyright © 2020 Eclipse Foundation. All rights reserved.