SmallRye Config provides a few enhancements and extensions to MicroProfile Config
Another way to create a
ConfigSource is via the
ConfigSourceFactory. The difference between the SmallRye Factory
and the standard way to create a
ConfigSource as specified in MicroProfile Config, is the Factory ability to provide
a context with access to the available configuration. With the
ConfigSourceFactory it is possible to bootstrap a
ConfigSource that configures itself with previously initialized
By implementing ConfigSourceFactory,
a list of
ConfigSources may be provided via the
Iterable<ConfigSource> getConfigSources(ConfigSourceContext context)
ConfigSourceFactory may also assign a priority by overriding the default method
OptionalInt getPriority(). This is only used to sort multiple factories during initialization. Once all the factories
are initialized, the provided
ConfigSources will use their own ordinal and be sorted with all
available in the
When the Factory is initializing, the provided
ConfigSourceContext may call the method
ConfigValue getValue(String name). This method lookups configuration names in all
ConfigSources that were already
initialized by the
Config instance, including sources with lower ordinals than the ones defined in the
ConfigSources provided by a
ConfigSourceFactory is not taken into account to configure other
sources produced by a lower priority
Registration of a
ConfigSourceFactory is done via the
ServiceLoader mechanism by providing the
implementation classes in a
META-INF/services/io.smallrye.config.ConfigSourceFactory file. Alternatively, factories
may be registered via the Programmatic API in
In addition to the default Config Sources specified by MicroProfile Config (Environment Variables, System Properties
microprofile-config.properties file), SmallRye Config provides the following additional Sources:
Creates a ConfigSource from Java
Map<String, String> objects or a properties file (referenced by
its URL). Check
Creates a Config Source with
ConfigValue support from a properties file (referenced by its URL).
ConfigValue is a metadata object, containing additional information to each configuration. This includes the
Config Source origin, ordinal, or the line number from where the Config was loaded. This is useful for debugging
Creates a ConfigSource that will look into a directory where each file corresponds to a property (the file name is the property key and its textual content is the property value).
For example, if a directory structure looks like:
foo/ |__num.max |__num.size
new FileSystemConfigSource("foo") will provide 2 properties:
And their values is the file content.
Nested directories are not supported.
The same mapping rules as defined for environment variables are applied, so the FileSystemConfigSource will search for a given property name (e.g. com.ACME.size):
Exact match (i.e. com.ACME.size)
Replace each character that is neither alphanumeric nor _ with _ (i.e. com_ACME_size)
Replace each character that is neither alphanumeric nor _ with _; then convert the name to upper case (i.e. COM_ACME_SIZE)
To use the FileSystem Config Source, add the following to your Maven
<dependency> <groupId>io.smallrye.config</groupId> <artifactId>smallrye-config-source-file-system</artifactId> <version>2.4.0</version> </dependency>
This Config Source register itself with the application if the dependency is present. Use the configuration property
smallrye.config.source.file.locations to set the directory paths to lookup additional configurations.
It accepts multiple locations separated by a comma and each must represent a valid URI to a directory.
ConfigSource implementation to support HOCON file format.
This Configuration Source will be looking for the following file
META-INF/microprofile-config.conf and will be loaded
with a lower ordinal than the default sources. The loading ordinal is
This Config Source allows you to use a
yaml file to describe your configuration. By default, the YAML Config Source
loads the configuration from the file
This Config Source has a higher priority than the default
Config Source implementation to support Apache Zookeeper.
The benefits are that configurations can be shared across applications and a future version will allow applications to subscribe to updates to the configuration parameters.
To use the Zookeeper Config Source, add the following to your Maven
<dependency> <groupId>io.smallrye.config</groupId> <artifactId>smallrye-config-source-zookeeper</artifactId> <version>2.4.0</version> </dependency>
This Config Source will automatically register with your application.
You also need to bootstrap your application with the location of your Zookeeper server and a unique identifier for your
application. Add the following to
src/main/resources/META-INF/microprofile-config.properties or create equivalent
Any properties that are looked up via the Config API or Injected will be looked up in Zookeeper in addition to the default MicroProfile Config locations.
The ConfigSource will store the following znodes in the specified Zookeeper server
/applicationId/propertyName = value.
This Config Source has a lower priority than the default Sources and thus will not override property files or Environment Variables.