Configuring your Quarkus applications
Abstract
Preface Copy linkLink copied to clipboard!
As an application developer, you can use Red Hat build of Quarkus to create microservices-based applications written in Java that run on OpenShift and serverless environments. Applications compiled to native executables have small memory footprints and fast startup times.
This guide describes how to configure a Quarkus application using the Eclipse MicroProfile Config method or YAML format. The procedures include configuration examples created using the Quarkus config-quickstart exercise.
Prerequisites
OpenJDK (JDK) 11 is installed and the
JAVA_HOMEenvironment variable specifies the location of the Java SDK.- Log in the Red Hat Customer Portal to download the Red Hat build of Open JDK from the Software Downloads page.
Apache Maven 3.6.3 or higher is installed.
- Download Maven from the Apache Maven Project website.
Have Maven configured to use artifacts from the Quarkus Maven repository.
- To learn how to configure Maven settings see Getting started with Quarkus.
Making open source more inclusive Copy linkLink copied to clipboard!
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
Chapter 1. Red Hat build of Quarkus configuration options Copy linkLink copied to clipboard!
Configuration options enable you to change the settings of your application in a single configuration file. Quarkus supports configuration profiles that let you group related properties and switch between profiles as required.
You can use the MicroProfile Config specification from the Eclipse MicroProfile project to inject configuration properties into your application and configure them using a method defined in your code. By default, Quarkus reads properties from the application.properties file located in the src/main/resources directory.
By adding the config-yaml dependency to your project pom.xml file you can add your application properties in the application.yaml file using the YAML format.
Quarkus can also read application properties from different sources, such as the file system, database, or any source that can be loaded by a Java application.
Chapter 2. Creating the configuration quickstart project Copy linkLink copied to clipboard!
The config-quickstart project lets you get up and running with a simple Quarkus application using Apache Maven and the Quarkus Maven plug-in. The following procedure demonstrates how you can create a Quarkus Maven project.
Procedure
In a command terminal, enter the following command to verify that Maven is using JDK 11 and that the Maven version is 3.6.3 or higher:
mvn --version
mvn --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow - If the preceding command does not return JDK 11, add the path to JDK 11 to the PATH environment variable and enter the preceding command again.
To generate the project, enter the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command creates the following elements in the
./config-quickstartdirectory:- The Maven structure
-
An
org.acme.config.GreetingResourceresource -
A landing page that is accessible on
http://localhost:8080after you start the application -
Example
Dockerfilefile insrc/main/docker - The application configuration file
An associated test
NoteAlternatively, you can download a Quarkus Maven project to use in this tutorial from the Quarkus quickstart archive or clone the
Quarkus QuickstartsGit repository. The exercise is located in theconfig-quickstartdirectory.
Chapter 3. Generating an example configuration file for your Quarkus application Copy linkLink copied to clipboard!
You can create an application.properties.example file with all of the available configuration values and documentation for the extensions your application is configured to use. You can repeat this procedure after you install a new extension to see what additional configuration options have been added.
Prerequisites
- You have a Quarkus Maven project.
Procedure
To create an
application.properties.examplefile, enter the following command:./mvnw quarkus:generate-config
./mvnw quarkus:generate-configCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command creates the
application.properties.examplefile in thesrc/main/resources/directory. The file contains all of the configuration options exposed through the extensions that you installed. These options are commented out and have a default value where applicable.The following example shows the HTTP port configuration entry from the
application.properties.examplefile:#quarkus.http.port=8080
#quarkus.http.port=8080Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 4. Injecting configuration values into your Quarkus application Copy linkLink copied to clipboard!
Red Hat build of Quarkus uses the MicroProfile Config feature to inject configuration data into the application. You can access the configuration through context and dependency injection (CDI) or by using a method defined in your code.
You can use the @ConfigProperty annotation to map an object property to a key in the MicroProfile ConfigSources file of your application. This procedure shows you how to inject an individual property configuration into a Quarkus config-quickstart project.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
-
Open the
src/main/resources/application.propertiesfile. Add configuration properties to your configuration file where
<key>is the property name and<value>is the value of the property:<key>=<value>
<key>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows how to set the values for the
greeting.messageand thegreeting.nameproperties in the Quarkusconfig-quickstartproject:greeting.message = hello greeting.name = quarkus
greeting.message = hello greeting.name = quarkusCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantUse
quarkusas a prefix to Quarkus properties.Review the
GreetingResource.javafile and make sure it includes the following import statements:import org.eclipse.microprofile.config.inject.ConfigProperty; import java.util.Optional;
import org.eclipse.microprofile.config.inject.ConfigProperty; import java.util.Optional;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the equivalent properties by annotating them with the following syntax:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- If you do not provide a value for this property, the application will fail and throw the following exception message:
javax.enterprise.inject.spi.DeploymentException: No config value of type [class java.lang.String] exists for: greeting.message - 2
- If you do not provide a value for the
greeting.suffix, Quarkus resolves it to the default value. - 3
- If the
Optionalparameter does not have a value, it returns no value forgreeting.name.
NoteTo inject a configured value, you can use
@ConfigProperty. The@Injectannotation is not necessary for members annotated with@ConfigProperty.Edit your
hellomethod to return the following message:@GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return message + " " + name.orElse("world") + suffix; }@GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return message + " " + name.orElse("world") + suffix; }Copy to Clipboard Copied! Toggle word wrap Toggle overflow To compile your Quarkus application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that the endpoint returns the message, enter the following command in a new terminal window:
curl http://localhost:8080/greeting
curl http://localhost:8080/greetingCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command returns the following output:
hello quarkus!
hello quarkus!Copy to Clipboard Copied! Toggle word wrap Toggle overflow - To stop the application, press CTRL+C
4.1. Annotating a class with @ConfigProperties Copy linkLink copied to clipboard!
As an alternative to injecting multiple related configuration values individually, you can use the @io.quarkus.arc.config.ConfigProperties annotation to group configuration properties. The following procedure demonstrates the use of @ConfigProperties annotation on the Quarkus config-quickstart project.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Review the
GreetingResource.javafile and make sure it includes the following import statements:package org.acme.config; import java.util.Optional; import javax.inject.Inject;
package org.acme.config; import java.util.Optional; import javax.inject.Inject;Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Create a file
GreetingConfiguration.javain thesrc/main/java/org/acme/configdirectory. Add the
@ConfigPropertiesand@Optionalimports to theGreetingConfiguration.javafile:package org.acme.config; import io.quarkus.arc.config.ConfigProperties; import java.util.Optional;
package org.acme.config; import io.quarkus.arc.config.ConfigProperties; import java.util.Optional;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
GreetingConfigurationclass for thegreetingproperties in yourGreetingConfiguration.javafile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Inject the attribute into the
GreetingResourceclass using the context and dependency injection (CDI)@Injectannotation:@Inject GreetingConfiguration greetingConfiguration;
@Inject GreetingConfiguration greetingConfiguration;Copy to Clipboard Copied! Toggle word wrap Toggle overflow To compile your application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantIf you do not provide values for the class properties, the application fails and a
javax.enterprise.inject.spi.DeploymentExceptionis thrown indicating a missing value. This does not apply toOptionalfields and fields with a default value.
4.2. Using nested object configuration Copy linkLink copied to clipboard!
You can define a nested class inside an existing class. This procedure demonstrates how to create a nested class configuration in the Quarkus config-quickstart project.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Review the
GreetingConfiguration.javafile and make sure it includes the following import statements:import io.quarkus.arc.config.ConfigProperties; import java.util.Optional; import java.util.List;
import io.quarkus.arc.config.ConfigProperties; import java.util.Optional; import java.util.List;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the configuration in your
GreetingConfiguration.javafile using the@ConfigPropertiesannotation.The following example shows the configuration of the
GreetingConfigurationclass and its properties:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add a nested class configuration similar to the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example shows a nested class
HiddenConfig. The name of the field, in this casehidden, determines the name of the properties bound to the object.Add the equivalent configuration properties to your
application.propertiesfile.The following example shows the value of properties for the
GreetingConfigurationandHiddenConfigclasses:greeting.message = hello greeting.name = quarkus greeting.hidden.prize-amount=10 greeting.hidden.recipients=Jane,John
greeting.message = hello greeting.name = quarkus greeting.hidden.prize-amount=10 greeting.hidden.recipients=Jane,JohnCopy to Clipboard Copied! Toggle word wrap Toggle overflow To compile your application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Classes annotated with @ConfigProperties can be annotated with Bean Validation annotations similar to the following example:
Your project must include the quarkus-hibernate-validator dependency.
4.3. Annotating an interface with @ConfigProperties Copy linkLink copied to clipboard!
An alternative method for managing properties is to define them as an interface. If you annotate an interface with @ConfigProperties, the interface can extend other interfaces, and you can use methods from the entire interface hierarchy to bind properties.
This procedure shows an implementation of the GreetingConfiguration class as an interface in the Quarkus config-quickstart project.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Review the
GreetingConfiguration.javafile and make sure it includes the following import statements:package org.acme.config; import io.quarkus.arc.config.ConfigProperties; import org.eclipse.microprofile.config.inject.ConfigProperty; import java.util.Optional;
package org.acme.config; import io.quarkus.arc.config.ConfigProperties; import org.eclipse.microprofile.config.inject.ConfigProperty; import java.util.Optional;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add a
GreetingConfigurationclass as an interface to yourGreetingConfiguration.javafile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- You must set the
@ConfigPropertyannotation because the name of the configuration property does not follow the getter method naming conventions. - 2
- In this example,
namewas not set so the corresponding property will begreeting.suffix. - 3
- You do not need to specify the
@ConfigPropertyannotation because the method name follows the getter method naming conventions (greeting.namebeing the corresponding property) and no default value is needed.
To compile your application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantIf you do not provide a value for an interface field, the application fails and an
javax.enterprise.inject.spi.DeploymentExceptionis thrown indicating a missing value. This does not apply toOptionalfields and fields with a default value.
Chapter 5. Accessing the configuration from code Copy linkLink copied to clipboard!
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.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
Chapter 6. Setting configuration properties Copy linkLink copied to clipboard!
By default, Quarkus reads properties from the application.properties file located in the src/main/resources directory. If you change build properties, make sure to repackage your application.
Quarkus configures most properties during build time. Extensions can define properties as overridable at run time, for example the database URL, a user name, and a password which can be specific to your target environment.
Prerequisites
- You have a Quarkus Maven project.
Procedure
To package your Quarkus project, enter the following command:
./mvnw clean package
./mvnw clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use one of the following methods to set the configuration properties:
Setting system properties:
Enter the following command where
<key>is the name of the configuration property you want to add and<value>is the value of the property:java -D<key>=<value> -jar target/myapp-runner.jar
java -D<key>=<value> -jar target/myapp-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to set the value of the
quarkus.datasource.passwordproperty, enter the following command:java -Dquarkus.datasource.password=youshallnotpass -jar target/myapp-runner.jar
java -Dquarkus.datasource.password=youshallnotpass -jar target/myapp-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow Setting environment variables:
Enter the following command where
<key>is the name of the configuration property you want to set and<value>is the value of the property:export <key>=<value> ; java -jar target/myapp-runner.jar
export <key>=<value> ; java -jar target/myapp-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteEnvironment variable names follow the conversion rules of Eclipse MicroProfile. Convert the name to upper case and replace any character that is not alphanumeric with an underscore (
_).Using an environment file:
Create an
.envfile in your current working directory and add configuration properties where<key>is the property name and<value>is the value of the property:<key>=<value>
<key>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor development mode, this file can be located in the root directory of your project, but it is advised to not track the file in version control. If you create an
.envfile in the root directory of your project, you can define keys and values that the program reads as properties.Using the
application.propertiesfile.Place the configuration file in
$PWD/config/application.propertiesdirectory where the application runs so any runtime properties defined in that file will override the default configuration.NoteYou can also use the
config/application.propertiesfeatures in development mode. Place theconfig/application.propertiesinside thetargetdirectory. Any cleaning operation from the build tool, for examplemvn clean, will remove theconfigdirectory as well.
Chapter 7. Using configuration profiles Copy linkLink copied to clipboard!
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.
7.1. Setting a custom configuration profile Copy linkLink copied to clipboard!
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 -D<key>=<value> quarkus:<profile>
mvn -D<key>=<value> quarkus:<profile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Set the <quarkus_profile> environment 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, Quarkus is in prod mode.
Chapter 8. Setting custom configuration sources Copy linkLink copied to clipboard!
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-quickstartproject.
Procedure
Create an
ExampleConfigSourceProvider.javafile within your project and add the following imports:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a class implementing the
ConfigSourceProviderinterface and make sure to override itsgetConfigSourcesmethod to return a list ofConfigSourceobjects:The following example shows an implementation of a custom
ConfigSourceProviderand aConfigSourceclasses:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Create the
org.eclipse.microprofile.config.spi.ConfigSourceProviderservice file in theMETA-INF/services/directory. Open the
org.eclipse.microprofile.config.spi.ConfigSourceProviderfile and add the fully qualified name of your custom ConfigSourceProvider class:org.acme.config.ExampleConfigSourceProvider
org.acme.config.ExampleConfigSourceProviderCopy to Clipboard Copied! Toggle word wrap Toggle overflow To compile the application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow When you restart your application, Quarkus picks up the custom configuration provider.
Chapter 9. Using custom configuration converters as configuration values Copy linkLink copied to clipboard!
You can store custom types as configuration values by implementing org.eclipse.microprofile.config.spi.Converter<T> and adding its fully qualified class name into the META-INF/services/org.eclipse.microprofile.config.spi.Converter file.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Include the fully qualified class name of the converter in your
META-INF/services/org.eclipse.microprofile.config.spi.Converterservice file as shown in the following example:org.acme.config.MicroProfileCustomValueConverter org.acme.config.SomeOtherConverter org.acme.config.YetAnotherConverter
org.acme.config.MicroProfileCustomValueConverter org.acme.config.SomeOtherConverter org.acme.config.YetAnotherConverterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Implement the converter class to override the convert method:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYour custom converter class must be
publicand must have apublicno-argument constructor. Your custom converter class cannot beabstract.Use your custom type as a configuration value:
@ConfigProperty(name = "configuration.value.name") MicroProfileCustomValue value;
@ConfigProperty(name = "configuration.value.name") MicroProfileCustomValue value;Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.1. Setting custom converters priority Copy linkLink copied to clipboard!
The default priority for all Quarkus core converters is 200 and for all other converters it is 100. However, you can set a higher priority for your custom converters using the javax.annotation.Priority annotation.
The following procedure demonstrates an implementation of a custom converter MicroProfileCustomValue that is assigned a priority of 150 and will take precedence over MicroProfileCustomValueConverter which has a value of 100.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Add the following import statements to your service file:
package org.acme.config; import javax.annotation.Priority; import org.eclipse.microprofile.config.spi.Converter;
package org.acme.config; import javax.annotation.Priority; import org.eclipse.microprofile.config.spi.Converter;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set a priority for your custom converter by annotating the class with the
@Priorityannotation and passing it a priority value:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you add a new converter, you must list it in the
META-INF/services/org.eclipse.microprofile.config.spi.Converterservice file.
Chapter 10. Adding YAML configuration support Copy linkLink copied to clipboard!
Red Hat build of Quarkus supports YAML configuration files through the SmallRye Config implementation of Eclipse MicroProfile Config. You can add the Quarkus Config YAML extension and use YAML over properties for configuration. Quarkus supports using application.yml as well as application.yaml as the name of the YAML file.
The YAML configuration file takes precedence over the application.properties file. The recommended approach is to delete the application.properties file and use only one type of configuration file to avoid errors.
Procedure
Use one of the following methods to add the YAML extension in your project:
Open the
pom.xmlfile and add thequarkus-config-yamlextension as a dependency:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-config-yaml</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-config-yaml</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To add the
quarkus-config-yamlextension from the command line, enter the following command from your project directory:./mvnw quarkus:add-extension -Dextensions="quarkus-config-yaml"
./mvnw quarkus:add-extension -Dextensions="quarkus-config-yaml"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.1. Using nested object configuration with YAML Copy linkLink copied to clipboard!
You can define a nested class inside an already existing class. The following YAML configuration file example shows how you can set nested properties in your Quarkus application using the YAML format.
Prerequisites
- You have an existing Quarkus project that can read YAML configuration files.
Procedure
To start Quarkus in development mode, enter the following command in the directory that contains your Quarkus application
pom.xmlfile:./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Open your YAML configuration file.
- Add a nested class configuration similar to the following syntax:
10.2. Setting custom configuration profiles with YAML Copy linkLink copied to clipboard!
Red Hat build of Quarkus lets you create profile dependent configurations and switch between them as required.The following procedure demonstrates how you can provide a profile dependent configuration with YAML.
Prerequisites
- You have a Quarkus project configured to read YAML configuration files.
Procedure
- Open your YAML configuration file.
To set a profile dependent configuration, add the profile name before defining the key-value pairs using the
”%profile”syntax:In the following example the PostgreSQL database is configured to be available at the
jdbc:postgresql://localhost:5432/some-databaseURL when Quarkus runs in the development mode:Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you stopped the application, enter the following command to restart it:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
10.3. Managing configuration key conflicts Copy linkLink copied to clipboard!
Structured formats such as YAML only support a subset of the possible configuration namespace. The following procedure shows a solution of a conflict between two configuration properties, quarkus.http.cors and quarkus.http.cors.methods, where one property is the prefix of another.
Prerequisites
- You have a Quarkus project configured to read YAML configuration files.
Procedure
- Open your YAML configuration file.
To define a YAML property as a prefix of another property, add a tilde (
~) in the scope of the property as shown in the following example:quarkus: http: cors: ~: true methods: GET,PUT,POSTquarkus: http: cors: ~: true methods: GET,PUT,POSTCopy to Clipboard Copied! Toggle word wrap Toggle overflow To compile your Quarkus application in development mode, enter the following command from the project directory:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can use YAML keys for conflicting configuration keys at any level because they are not included in the assembly of configuration property name.
Chapter 11. Updating the functional test to validate configuration changes Copy linkLink copied to clipboard!
Before you test the functionality of your application, you must update the functional test to reflect the changes you made to the endpoint of your application. The following procedure shows how you can update your testHelloEndpoint method on the Quarkus config-quickstart project.
Procedure
-
Open the
GreetingResourceTest.javafile. Update the content of the
testHelloEndpointmethod:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 12. Packaging and running your Quarkus application Copy linkLink copied to clipboard!
After you compile your Quarkus project, you can package it in a JAR file and run it from the command line.
Prerequisites
- You have compiled your Quarkus project.
Procedure
To package your Quarkus project, enter the following command in the
rootdirectory:./mvnw clean package
./mvnw clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command produces the following JAR files in the
/targetdirectory:-
config-quickstart-1.0-SNAPSHOT.jar: Contains the classes and resources of the projects. This is the regular artifact produced by the Maven build. -
config-quickstart-1.0-SNAPSHOT-runner.jar: Is an executable JAR file. Be aware that this file is not an uber-JAR file because the dependencies are copied into thetarget/libdirectory.
-
- If development mode is running, press CTRL+C to stop development mode. If you do not do this, you will have a port conflict.
To run the application, enter the following command:
java -jar target/config-quickstart-1.0-SNAPSHOT-runner.jar
java -jar target/config-quickstart-1.0-SNAPSHOT-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe
Class-Pathentry of theMANIFEST.MFfile from therunnerJAR file explicitly lists the JAR files from thelibdirectory. If you want to deploy your application from another location, you must copy therunnerJAR file as well as thelibdirectory.
Chapter 13. Additional resources Copy linkLink copied to clipboard!
Revised on 2021-04-19 08:53:43 UTC