Chapter 8. Setting custom configuration sources
By default, Quarkus reads properties from the application.properties file. However, because Quarkus supports the MicroProfile Config feature, you can introduce custom configuration sources and load a configuration from another source.
You can introduce custom configuration sources for your configured values by providing classes that implement the org.eclipse.microprofile.config.spi.ConfigSource and the org.eclipse.microprofile.config.spi.ConfigSourceProvider interfaces. This procedure demonstrates how you can implement a custom configuration source on your Quarkus project.
Prerequisite
-
You have created the Quarkus
config-quickstartproject.
Procedure
Create an
ExampleConfigSourceProvider.javafile within your project and add the following imports:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a class implementing the
ConfigSourceProviderinterface and make sure to override itsgetConfigSourcesmethod to return a list ofConfigSourceobjects:The following example shows an implementation of a custom
ConfigSourceProviderand aConfigSourceclasses:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Create the
org.eclipse.microprofile.config.spi.ConfigSourceProviderservice file in theMETA-INF/services/directory. Open the
org.eclipse.microprofile.config.spi.ConfigSourceProviderfile and add the fully qualified name of your custom ConfigSourceProvider class:org.acme.config.ExampleConfigSourceProvider
org.acme.config.ExampleConfigSourceProviderCopy to Clipboard Copied! Toggle word wrap Toggle overflow To compile the application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow When you restart your application, Quarkus picks up the custom configuration provider.