Chapter 4. Configuration
In this chapter, you’ll learn the following about setting configuration parameters:
-
How to configure a Quarkus service
-
How to inject configuration parameters in the service
-
How to apply values depending on the environment
-
How to correctly configure the logging system
-
How to create customizations for the configuration system
4.1 Configuring the Application with Custom Properties
Problem
You want to configure the Quarkus application with custom properties.
Solution
Quarkus makes use of a number of the Eclipse MicroProfile specifications. One of those is the Configuration specification; however, to simplify configuration, Quarkus uses just one file for all configurations, application.properties, which must be placed in the root of the classpath.
This file can be used to configure Quarkus properties such as logging or default path, Quarkus extensions like data source or Kafka, or custom properties that you define for the application. You are going to see all of them in the book, but in this recipe, you’ll see the latter one.
Open the src/main/resources/application.properties file and add the following property:
greeting.message=Hello World
You can inject the property value defined in application.properties by using the org.eclipse.microprofile.config.inject.ConfigProperty annotation in a field.
Open org.acme.quickstart.GreetingResource.java and inject greeting.message property value:
@ConfigProperty(name="greeting.message")Stringmessage ...