이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 7. Property expressions


Property expressions are combinations of property references and plain text strings that you can use to substitute values of properties in your configuration.

Much like a variable, you can use a property expression in Quarkus to substitute a value of a configuration property instead of hardcoding it. A property expression is resolved when java.util.Properties reads the value of the property from a configuration source in your application.

This means that if a configuration property is read form your configuration at compile time, the property expression is also resolved at compile time. If the configuration property is overriden at runtime, its value is resolved at runtime.

Property expressions can be resolved using more than one configuration source. This means that you can use a value of a property that is defined in one configuration source to expand a property expression that you use in another configuration source.

If the value of a property in an expression cannot be resolved, and you do not set a default value for the expression, your application encounters a NoSuchElementException.

7.1. Example usage of property expressions

In this section you can find examples of how you can use property expressions to achieve greater flexibility when configuring of your Quarkus application.

  • Substituting the value of a configuration property:

    You can use a property expression to avoid hardcoding property values in you configuration. Use the ${<property_name>} syntax to write an expression that references a configuration property, as shown in the following example:

    application.properties

    remote.host=quarkus.io
    callable.url=https://${remote.host}/
    Copy to Clipboard Toggle word wrap

    The value of the callable.url property resolves to https://quarkus.io/.

  • Setting a property value that is specific to a particular configuration profile:

    In the following example, the %dev configuration profile and the default configuration profile are set to use data source connection URLs with different host addresses. Depending on the configuration profile with which you start your application, your data source driver uses the database URL that you set for the profile:

    application.properties

    %dev.quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false
    quarkus.datasource.jdbc.url=jdbc:mysql://remotehost:3306/mydatabase?useSSL=false
    Copy to Clipboard Toggle word wrap

    You can achieve the same result in a simplified way by setting a different value of the custom application.server property for each configuration profile. You can then reference the property in the database connection URL of your application, as shown in the example:

    application.properties

    %dev.application.server=localhost
    application.server=remotehost
    
    quarkus.datasource.jdbc.url=jdbc:mysql://${application.server}:3306/mydatabase?useSSL=false
    Copy to Clipboard Toggle word wrap

    The application.server property resolves to the appropriate value depending on the profile that you choose when you run your application.

  • Setting a default value of a property expression:

    You can define a default value for a property expression. Quarkus uses the default value if the value of the property that is required to expand the expression is not resolved from any of your configuration sources. You can set a default value of an expression using the following syntax:

    ${<expression>:<default_value>}
    Copy to Clipboard Toggle word wrap

    In the following example, the property expression in the data source URL uses mysql.db.server as the default value of the application.server property:

    application.properties

    quarkus.datasource.jdbc.url=jdbc:mysql://${application.server:mysql.db.server}:3306/mydatabase?useSSL=false
    Copy to Clipboard Toggle word wrap

  • Nesting property expressions:

    You can compose property expressions by nesting a property expression inside another property expression. When nested property expressions are expanded, the inner expression is expanded first:

    ${<outer_property_expression>${<inner_property_expression>}}
    Copy to Clipboard Toggle word wrap
  • Multiple property expressions:

    You can join two or more property expression together as shown below:

    ${<first_property>}${<second_property>}
    Copy to Clipboard Toggle word wrap
  • Combining property expressions with environment variables:

    You can use property expressions to substitute the values of environment variables. The expression in the following example substitutes the value that is set for the HOST environment variable as the value of the application.host property. When HOST environment variable is not set, application.host uses the value of the remote.host property as the default:

    application.properties

    remote.host=quarkus.io
    application.host=${HOST:${remote.host}}
    Copy to Clipboard Toggle word wrap

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat