diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index d659e13de759..0ed946c549ee 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -84,6 +84,7 @@ * @author Pavel Anisimov * @author Scott Frederick * @author Moritz Halbritter + * @author Yanming Zhou */ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGenerationTests { @@ -492,6 +493,32 @@ public record ExampleRecord(String someString, Integer someInteger) { assertThat(metadata).has(Metadata.withProperty("implicit.some-integer")); } + @Test + void recordPropertiesWithName() { + String source = """ + @org.springframework.boot.configurationsample.ConfigurationProperties("implicit") + public record ExampleRecord( + @org.springframework.boot.configurationsample.Name("for") String forString) { + } + """; + ConfigurationMetadata metadata = compile(source); + assertThat(metadata).has(Metadata.withProperty("implicit.for")); + } + + @Test + void recordPropertiesWithNameAndDefaultValue() { + String source = """ + @org.springframework.boot.configurationsample.ConfigurationProperties("implicit") + public record ExampleRecord( + @org.springframework.boot.configurationsample.Name("for") + @org.springframework.boot.configurationsample.DefaultValue("example") + String forString) { + } + """; + ConfigurationMetadata metadata = compile(source); + assertThat(metadata).has(Metadata.withProperty("implicit.for", String.class).withDefaultValue("example")); + } + @Test void recordPropertiesWithDefaultValues() { String source = """ diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Name.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Name.java index 2d8969968dc6..5562172ffbe8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Name.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Name.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -27,8 +27,9 @@ * dependency on the real annotation). * * @author Phillip Webb + * @author Yanming Zhou */ -@Target({ ElementType.PARAMETER, ElementType.FIELD }) +@Target({ ElementType.FIELD, ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Name { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Name.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Name.java index 29134a495f0e..0bfcee054fea 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Name.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Name.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -32,10 +32,11 @@ * * @author Phillip Webb * @author Lasse Wulff + * @author Yanming Zhou * @since 2.4.0 */ @Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD, ElementType.PARAMETER }) +@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.RECORD_COMPONENT }) @Documented public @interface Name {