From 7dce772d67b185bee178aa45b5966458bd4ab493 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 3 Mar 2022 11:49:40 +0000 Subject: [PATCH] Polish "Update placeholder docs to mention env vars and default values" See gh-30012 --- .../src/docs/asciidoc/features/external-config.adoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/external-config.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/external-config.adoc index 4853cc24a46..659a3f3c49a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/external-config.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/external-config.adoc @@ -444,17 +444,20 @@ For example, if a secret named `db.password` is mounted at location `/run/secret [[features.external-config.files.property-placeholders]] ==== 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:default}` property-placeholder syntax can be used anywhere within a value. +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}`. -For example, the following file will set `app.description` to "`MyApp is a Spring Boot application written by john.doe`": +The use of placeholders with and without defaults is shown in the following example: [source,yaml,indent=0,subs="verbatim",configblocks] ---- app: name: "MyApp" - description: "${app.name} is a Spring Boot application written by ${USERNAME:john.doe}" + description: "${app.name} is a Spring Boot application written by ${username:Unknown}" ---- +Assuming that the `username` property has not be set elsewhere, `app.description` will have the value `MyApp is a Spring Boot application written by Unknown`. + TIP: You can also use this technique to create "`short`" variants of existing Spring Boot properties. See the _<>_ how-to for details.