Using advanced configuration options

As we have already learned, Quarkus relies on the MicroProfile Config specification to inject configuration properties into our application. So far, we have used the default configuration file (named application.properties) to provide initial values for the application's initial settings.

Let's recap with a basic example of how to inject a property, including a default value for the attribute:

@Inject
@ConfigProperty(name="tempFileName", defaultValue="file.tmp")
String fileName;

In the preceding code, we are injecting an application property into the fileName variable. Note that property names should be carefully planned since Quarkus ships with an extensive set of system properties that can be used to manage its environment. Luckily, you don't need to have your documentation at hand to check for all the available system properties. As a matter of fact, you can use Maven's generate-config command to list all the built-in system properties, based on the extensions that you have currently installed:

mvn quarkus:generate-config

This command will create a file named application.properties.example under the src/main/resources folder. If you open this file, you will see that it contains a commented list of all the available configuration options, which are located under the quarkus namespace. Here is a brief excerpt of it:

# The name of the application.
# If not set, defaults to the name of the project.
#
#quarkus.application.name=

# The version of the application.
# If not set, defaults to the version of the project
#
#quarkus.application.version=

As a side note, you can choose a different filename for generate-command by adding the -Dfile=<filename> option.

In the upcoming sections, we will learn about some advanced configuration drills using the examples located in the Chapter08/advanced-config folder of this book's GitHub repository as references. We recommend importing the project into your IDE before you move on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.103.183