From 5c10ae2f0b95bbfec63be1f8b9ee91b6737468fa Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Fri, 18 Nov 2022 10:23:09 +0100 Subject: [PATCH] Revert "Remove unneeded NestedConfigurationProperty" This reverts commit 8048e2d6c233e6e3586bd7ecf95885f8ff3e6c61. --- .../src/docs/asciidoc/native-image/advanced-topics.adoc | 2 ++ .../advanced/nestedconfigurationproperties/MyProperties.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/advanced-topics.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/advanced-topics.adoc index d96aa6f6cc24..285758ebe009 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/advanced-topics.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/advanced-topics.adoc @@ -6,10 +6,12 @@ [[native-image.advanced.nested-configuration-properties]] === Nested Configuration Properties Reflection hints are automatically created for configuration properties by the Spring ahead-of-time engine. +Nested configuration properties, however, *must* be annotated with `@NestedConfigurationProperty`, otherwise they won't be detected and will not be bindable. include::code:MyProperties[] The example above produces configuration properties for `my.properties.name` and `my.properties.nested.number`. +Without the `@NestedConfigurationProperty` annotation on the `nested` field, the `my.properties.nested.number` property would not be bindable in a native image. NOTE: Please use public getters and setters, otherwise the properties will not be bindable. diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/nativeimage/advanced/nestedconfigurationproperties/MyProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/nativeimage/advanced/nestedconfigurationproperties/MyProperties.java index 33c4cccbf258..f4d064e05ffd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/nativeimage/advanced/nestedconfigurationproperties/MyProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/nativeimage/advanced/nestedconfigurationproperties/MyProperties.java @@ -17,12 +17,14 @@ package org.springframework.boot.docs.nativeimage.advanced.nestedconfigurationproperties; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; @ConfigurationProperties(prefix = "my.properties") public class MyProperties { private String name; + @NestedConfigurationProperty private Nested nested = new Nested(); // @fold:on // getters / setters...