mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 20:19:06 +00:00
Allow NestedConfigurationProperty to be set on a record accessor
Closes gh-50096
This commit is contained in:
+2
-1
@@ -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
|
||||
|
||||
+10
@@ -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);
|
||||
|
||||
+38
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user