Este conteúdo não está disponível no idioma selecionado.
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 either 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.propertiesfile, use the following syntax whereDATABASE.NAMEis the name of a property that is assigned to adatabaseNamevariable:String databaseName = ConfigProvider.getConfig().getValue("DATABASE.NAME", String.class);String databaseName = ConfigProvider.getConfig().getValue("DATABASE.NAME", String.class);Copy to Clipboard Copied! Toggle word wrap Toggle overflow To access a configuration of a property that might not be defined in your
application.propertiesfile, use the following syntax:Optional<String> maybeDatabaseName = ConfigProvider.getConfig().getOptionalValue("DATABASE.NAME", String.class);Optional<String> maybeDatabaseName = ConfigProvider.getConfig().getOptionalValue("DATABASE.NAME", String.class);Copy to Clipboard Copied! Toggle word wrap Toggle overflow