Skip to Content
Quarkus Cookbook
book

Quarkus Cookbook

by Alex Soto Bueno, Jason Porter
July 2020
Intermediate to advanced
392 pages
7h 20m
English
O'Reilly Media, Inc.
Book available
Content preview from Quarkus Cookbook

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") 
String message ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Cookbook, 4th Edition

Java Cookbook, 4th Edition

Ian F. Darwin
Vert.x in Action

Vert.x in Action

Julien Ponge
React Cookbook

React Cookbook

David Griffiths, Dawn Griffiths
JavaScript Cookbook, 3rd Edition

JavaScript Cookbook, 3rd Edition

Adam D. Scott, Matthew MacDonald, Shelley Powers

Publisher Resources

ISBN: 9781492062646Errata PageSupplemental Content