From 7b3c0a9e096501daf55271e1beb73550ced915c2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 27 Jul 2020 09:58:24 +0100 Subject: [PATCH] Advise against java.util.Optional configuration properties Closes gh-21868 --- .../src/main/asciidoc/spring-boot-features.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 9edf43f116..64531d1e97 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -949,6 +949,10 @@ You cannot use constructor binding with beans that are created by the regular Sp TIP: If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on the constructor that should be bound. +NOTE: The use of `java.util.Optional` with `@ConfigurationProperties` is not recommended as it is primarily intended for use as a return type. +As such, it is not well-suited to configuration property injection. +For consistency with properties of other types, if you do declare an `Optional` property and it has no value, `null` rather than an empty `Optional` will be bound. + [[boot-features-external-config-enabling]]