Chapter 5. Accessing the configuration from code


You can access the configuration by using a method defined in your code. You can achieve dynamic lookups or retrieve configured values from classes that are neither CDI beans or JAX-RS resources.

You can access the configuration using the org.eclipse.microprofile.config.ConfigProvider.getConfig() method. The getValue method of the Config object returns the values of the configuration properties.

Prerequisites

  • You have a Quarkus Maven project.

Procedure

  • Access the configuration using one of the following options:

    • To access a configuration of a property that is defined already in your application.properties file, use the following syntax where DATABASE.NAME is the name of a property that is assigned to a databaseName variable:

      String databaseName = ConfigProvider.getConfig().getValue("DATABASE.NAME", String.class);
      Copy to Clipboard Toggle word wrap
    • To access a configuration of a property that might not be defined in your application.properties file, use the following syntax:

      Optional<String> maybeDatabaseName = ConfigProvider.getConfig().getOptionalValue("DATABASE.NAME", String.class);
      Copy to Clipboard Toggle word wrap
Back to top
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

© 2025 Red Hat