Chapter 7. 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;
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());
NoteIt is not possible to access the current profile using the
@ConfigProperty("quarkus.profile")
method.
7.1. Setting a custom configuration profile
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.properties
file, where<key>
is the name of the property,<value>
is the property value, and<profile>
is the name of a profile:%<profile>.<key>=<value>
In the following example configuration, the value of
quarkus.http.port
is 9090 by default, and becomes 8181 when thedev
profile is activated:quarkus.http.port=9090 %dev.quarkus.http.port=8181
Use one of the following methods to enable a profile:
Set the
quarkus.profile
system property.To enable a profile using the
quarkus.profile
system property, enter the following command:mvn -D<key>=<value> quarkus:<profile>
Set the <quarkus_profile> environment variable.
To enable profile using an environment variable, enter the following command:
export <quarkus_profile>=<profile>
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
The following example shows a command that activates the
prod-aws
profile:./mvnw package -Dquarkus.profile=prod-aws java -jar target/myapp-runner.jar
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, Quarkus is in prod
mode.