Fix Kotlin example for empty @DefaultValue constructor binding
Closes gh-32177
This commit is contained in:
@@ -730,11 +730,10 @@ Default values can be specified using `@DefaultValue` on a constructor parameter
|
||||
The conversion service will be applied to coerce the `String` value to the target type of a missing property.
|
||||
|
||||
Referring to the previous example, if no properties are bound to `Security`, the `MyProperties` instance will contain a `null` value for `security`.
|
||||
If you wish you return a non-null instance of `Security` even when no properties are bound to it, you can use an empty `@DefaultValue` annotation to do so:
|
||||
To make it contain a non-null instance of `Security` even when no properties are bound to it (when using Kotlin, this will require the `username` and `password` parameters of `Security` to be declared as nullable as they do not have default values), use an empty `@DefaultValue` annotation:
|
||||
|
||||
include::code:nonnull/MyProperties[tag=*]
|
||||
|
||||
|
||||
NOTE: To use constructor binding the class must be enabled using `@EnableConfigurationProperties` or configuration property scanning.
|
||||
You cannot use constructor binding with beans that are created by the regular Spring mechanisms (for example `@Component` beans, beans created by using `@Bean` methods or beans loaded by using `@Import`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user