此内容没有您所选择的语言版本。

Chapter 10. Adding YAML configuration support


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.xml file and add the quarkus-config-yaml extension as a dependency:

      <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-config-yaml</artifactId>
      </dependency>
      Copy to Clipboard Toggle word wrap
    • To add the quarkus-config-yaml extension from the command line, enter the following command from your project directory:

      ./mvnw quarkus:add-extension -Dextensions="quarkus-config-yaml"
      Copy to Clipboard Toggle word wrap

10.1. Using nested object configuration with YAML

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

  1. To start Quarkus in development mode, enter the following command in the directory that contains your Quarkus application pom.xml file:

    ./mvnw quarkus:dev
    Copy to Clipboard Toggle word wrap
  2. Open your YAML configuration file.
  3. Add a nested class configuration similar to the following syntax:
# YAML supports comments
quarkus:
  datasource:
    url: jdbc:postgresql://localhost:5432/some-database
    driver: org.postgresql.Driver
    username: quarkus
    password: quarkus

# REST Client configuration property
org:
  acme:
    restclient:
      CountriesService/mp-rest/url: https://restcountries.eu/rest

# For configuration property names that use quotes, do not split the string inside the quotes.
quarkus:
  log:
    category:
      "io.quarkus.category":
        level: INFO
Copy to Clipboard Toggle word wrap

10.2. Setting custom configuration profiles with YAML

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

  1. Open your YAML configuration file.
  2. 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-database URL when Quarkus runs in the development mode:

    "%dev":
      quarkus:
        datasource:
          url: jdbc:postgresql://localhost:5432/some-database
          driver: org.postgresql.Driver
          username: quarkus
          password: quarkus
    Copy to Clipboard Toggle word wrap
  3. If you stopped the application, enter the following command to restart it:

    ./mvnw quarkus:dev
    Copy to Clipboard Toggle word wrap

10.3. Managing configuration key conflicts

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

  1. Open your YAML configuration file.
  2. 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,POST
    Copy to Clipboard Toggle word wrap
  3. To compile your Quarkus application in development mode, enter the following command from the project directory:

    ./mvnw quarkus:dev
    Copy to Clipboard Toggle word wrap
    Note

    You can use YAML keys for conflicting configuration keys at any level because they are not included in the assembly of configuration property name.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat