diff --git a/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/RecordParameterPropertyDescriptor.java b/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/RecordParameterPropertyDescriptor.java index 492cc5a2d30..d0d33148fa6 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/RecordParameterPropertyDescriptor.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/RecordParameterPropertyDescriptor.java @@ -48,7 +48,8 @@ class RecordParameterPropertyDescriptor extends ParameterPropertyDescriptor { @Override protected boolean isMarkedAsNested(MetadataGenerationEnvironment environment) { - return environment.getNestedConfigurationPropertyAnnotation(this.recordComponent) != null; + return environment.getNestedConfigurationPropertyAnnotation(this.recordComponent) != null + || environment.getNestedConfigurationPropertyAnnotation(getGetter()) != null; } @Override diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 7be6c313128..17ddc197368 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -35,6 +35,7 @@ import org.springframework.boot.configurationsample.deprecation.Dbcp2Configurati import org.springframework.boot.configurationsample.method.NestedPropertiesMethod; import org.springframework.boot.configurationsample.method.NestedPropertiesMethodImmutable; import org.springframework.boot.configurationsample.record.ExampleRecord; +import org.springframework.boot.configurationsample.record.NestedPropertiesOnMethodRecord; import org.springframework.boot.configurationsample.record.NestedPropertiesRecord; import org.springframework.boot.configurationsample.record.RecordWithGetter; import org.springframework.boot.configurationsample.recursive.RecursiveProperties; @@ -599,6 +600,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene assertThat(metadata).has(Metadata.withProperty("record-nested.inner.nested.my-nested-property")); } + @Test + void recordNestedMethod() { + ConfigurationMetadata metadata = compile(NestedPropertiesOnMethodRecord.class); + assertThat(metadata).has(Metadata.withGroup("record-nested.nested")); + assertThat(metadata).has(Metadata.withProperty("record-nested.nested.my-nested-property")); + assertThat(metadata).has(Metadata.withGroup("record-nested.inner.nested")); + assertThat(metadata).has(Metadata.withProperty("record-nested.inner.nested.my-nested-property")); + } + @Test void shouldNotMarkDbcp2UsernameOrPasswordAsDeprecated() { ConfigurationMetadata metadata = compile(Dbcp2Configuration.class); diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/NestedPropertiesOnMethodRecord.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/NestedPropertiesOnMethodRecord.java new file mode 100644 index 00000000000..25b14e54f5f --- /dev/null +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/NestedPropertiesOnMethodRecord.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.configurationsample.record; + +import org.springframework.boot.configurationsample.TestConfigurationProperties; +import org.springframework.boot.configurationsample.TestNestedConfigurationProperty; + +@TestConfigurationProperties("record-nested") +public record NestedPropertiesOnMethodRecord(String myProperty, NestedRecord nested, InnerPropertiesRecord inner) { + + @TestNestedConfigurationProperty + public NestedRecord nested() { + return this.nested; + } + + public record InnerPropertiesRecord(String myInnerProperty, NestedRecord nested) { + + @TestNestedConfigurationProperty + public NestedRecord nested() { + return this.nested; + } + } + +}