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-quickstart project.

Procedure

  1. Create an ExampleConfigSourceProvider.java file within your project and add the following imports:

    package org.acme.config;
    
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;
    
    import org.eclipse.microprofile.config.spi.ConfigSource;
    import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
    Copy to Clipboard Toggle word wrap
  2. Create a class implementing the ConfigSourceProvider interface and make sure to override its getConfigSources method to return a list of ConfigSource objects:

    The following example shows an implementation of a custom ConfigSourceProvider and a ConfigSource classes:

    public class ExampleConfigSourceProvider implements ConfigSourceProvider {
    
        private final int times = 2;
        private final String name = "example";
        private final String value = "value";
    
        @Override
        public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
            InMemoryConfigSource configSource = new InMemoryConfigSource(Integer.MIN_VALUE, "example config source");
            for (int i = 0; i < this.times; i++) {
                configSource.add(this.name + ".key" + (i + 1), this.value + (i + 1));
            }
            return Collections.singletonList(configSource);
        }
    
        private static final class InMemoryConfigSource implements ConfigSource {
    
            private final Map<String, String> values = new HashMap<>();
            private final int ordinal;
            private final String name;
    
            private InMemoryConfigSource(int ordinal, String name) {
                this.ordinal = ordinal;
                this.name = name;
            }
    
            public void add(String key, String value) {
                values.put(key, value);
            }
    
            @Override
            public Map<String, String> getProperties() {
                return values;
            }
    
            @Override
            public Set<String> getPropertyNames() {
                return values.keySet();
            }
    
            @Override
            public int getOrdinal() {
                return ordinal;
            }
    
            @Override
            public String getValue(String propertyName) {
                return values.get(propertyName);
            }
    
            @Override
            public String getName() {
                return name;
            }
        }
    }
    Copy to Clipboard Toggle word wrap
  3. Create the org.eclipse.microprofile.config.spi.ConfigSourceProvider service file in the META-INF/services/ directory.
  4. Open the org.eclipse.microprofile.config.spi.ConfigSourceProvider file and add the fully qualified name of your custom ConfigSourceProvider class:

    org.acme.config.ExampleConfigSourceProvider
    Copy to Clipboard Toggle word wrap
  5. To compile the application in development mode, enter the following command from the project directory:

    ./mvnw quarkus:dev
    Copy to Clipboard Toggle word wrap

    When you restart your application, Quarkus picks up the custom configuration provider.

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top