Relax @ConstructorBinding member class requirement

Update `@ConfigurationProperties` so that `@ConstructorBinding` classes
no longer need to repeat the annotation for their members.

Closes gh-18481
This commit is contained in:
Phillip Webb
2019-10-02 14:59:37 -07:00
parent e6bb7a0a6f
commit 386c0a60a7
6 changed files with 174 additions and 8 deletions

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2012-2019 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.configurationprocessor;
import org.junit.jupiter.api.Test;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.Metadata;
import org.springframework.boot.configurationsample.immutable.DeducedImmutableClassProperties;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Metadata generation tests for immutable properties deduced because they're nested.
*
* @author Phillip Webb
*/
class DeducedImmutablePropertiesMetadataGenerationTests extends AbstractMetadataGenerationTests {
@Test
void immutableSimpleProperties() {
ConfigurationMetadata metadata = compile(DeducedImmutableClassProperties.class);
assertThat(metadata).has(Metadata.withGroup("test").fromSource(DeducedImmutableClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("test.nested.name", String.class));
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2012-2019 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.immutable;
import org.springframework.boot.configurationsample.ConfigurationProperties;
import org.springframework.boot.configurationsample.ConstructorBinding;
/**
* Inner properties, in immutable format.
*
* @author Phillip Webb
*/
@ConfigurationProperties("test")
@ConstructorBinding
public class DeducedImmutableClassProperties {
private final Nested nested;
public DeducedImmutableClassProperties(Nested nested) {
this.nested = nested;
}
public Nested getNested() {
return this.nested;
}
public static class Nested {
private String name;
public Nested(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
}