Skip to content

Commit 7b3c0a9

Browse files
committed
Advise against java.util.Optional configuration properties
Closes gh-21868
1 parent 1622539 commit 7b3c0a9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ You cannot use constructor binding with beans that are created by the regular Sp
949949

950950
TIP: If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on the constructor that should be bound.
951951

952+
NOTE: The use of `java.util.Optional` with `@ConfigurationProperties` is not recommended as it is primarily intended for use as a return type.
953+
As such, it is not well-suited to configuration property injection.
954+
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.
955+
952956

953957

954958
[[boot-features-external-config-enabling]]

0 commit comments

Comments
 (0)