Property Placeholders
The values in application.properties
and application.yml
are filtered through the existing Environment
when they are used, so you can refer back to previously defined values (for example, from System properties or environment variables).
The standard ${name}
property-placeholder syntax can be used anywhere within a value.
Property placeholders can also specify a default value using a :
to separate the default value from the property name, for example ${name:default}
.
The use of placeholders with and without defaults is shown in the following example:
-
Properties
-
YAML
app.name=MyApp
app.description=${app.name} is a Spring Boot application written by ${username:Unknown}
app:
name: "MyApp"
description: "${app.name} is a Spring Boot application written by ${username:Unknown}"
Assuming that the username
property has not been set elsewhere, app.description
will have the value MyApp is a Spring Boot application written by Unknown
.
You should always refer to property names in the placeholder using their canonical form (kebab-case using only lowercase letters).
This will allow Spring Boot to use the same logic as it does when relaxed binding For example, |
You can also use this technique to create “short” variants of existing Spring Boot properties. See the Use ‘Short’ Command Line Arguments how-to for details. |