Este conteúdo não está disponível no idioma selecionado.
Chapter 8. Using configuration profiles
You can use different configuration profiles depending on your environment. Configuration profiles enable you to have multiple configurations in the same file and select between them using a profile name. Red Hat build of Quarkus has three configuration profiles. In addition, you can create your own custom profiles.
Quarkus default profiles:
- dev: Activated in development mode
- test: Activated when running tests
- prod: The default profile when not running in development or test mode
Prerequisites
- You have a Quarkus Maven project.
Procedure
Open your Java resource file and add the following import statement:
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.configuration.ProfileManager;Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display the current configuration profile, add a log invoking the
ProfileManager.getActiveProfile()method:LOGGER.infof("The application is starting with profile `%s`", ProfileManager.getActiveProfile());LOGGER.infof("The application is starting with profile `%s`", ProfileManager.getActiveProfile());Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIt is not possible to access the current profile using the
@ConfigProperty("quarkus.profile")method.
8.1. Setting a custom configuration profile Copiar o linkLink copiado para a área de transferência!
You can create as many configuration profiles as you want. You can have multiple configurations in the same file and you can select between them using a profile name.
Procedure
To set a custom profile, create a configuration property with the profile name in the
application.propertiesfile, where<key>is the name of the property,<value>is the property value, and<profile>is the name of a profile:%<profile>.<key>=<value>
%<profile>.<key>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the following example configuration, the value of
quarkus.http.portis 9090 by default, and becomes 8181 when thedevprofile is activated:quarkus.http.port=9090 %dev.quarkus.http.port=8181
quarkus.http.port=9090 %dev.quarkus.http.port=8181Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use one of the following methods to enable a profile:
Set the
quarkus.profilesystem property.To enable a profile using the
quarkus.profilesystem property, enter the following command:mvn -Dquarkus.profile=<value> quarkus:dev
mvn -Dquarkus.profile=<value> quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Set the
QUARKUS_PROFILEenvironment variable.To enable profile using an environment variable, enter the following command:
export QUARKUS_PROFILE=<profile>
export QUARKUS_PROFILE=<profile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe system property value takes precedence over the environment variable value.
To repackage the application and change the profile, enter the following command:
./mvnw package -Dquarkus.profile=<profile> java -jar target/myapp-runner.jar
./mvnw package -Dquarkus.profile=<profile> java -jar target/myapp-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows a command that activates the
prod-awsprofile:./mvnw package -Dquarkus.profile=prod-aws java -jar target/myapp-runner.jar
./mvnw package -Dquarkus.profile=prod-aws java -jar target/myapp-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The default Quarkus application runtime profile is set to the profile used to build the application. Red Hat build of Quarkus automatically selects a profile depending on your environment mode. For example, when your application is running as a JAR, Quarkus is in prod mode.