Drop ignoreNestedProperties attribute from @ConfigurationProperties

Closes gh-8657
pull/75/merge
Andy Wilkinson 8 years ago
parent 12dda513f9
commit abdc23905f

@ -65,13 +65,6 @@ public @interface ConfigurationProperties {
*/
boolean ignoreInvalidFields() default false;
/**
* Flag to indicate that when binding to this object fields with periods in their
* names should be ignored.
* @return the flag value (default false)
*/
boolean ignoreNestedProperties() default false;
/**
* Flag to indicate that when binding to this object unknown fields should be ignored.
* An unknown field could be a sign of a mistake in the Properties.

@ -38,7 +38,6 @@ import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
import org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler;
import org.springframework.boot.context.properties.bind.handler.IgnoreNestedPropertiesBindHandler;
import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler;
import org.springframework.boot.context.properties.bind.validation.ValidationBindHandler;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
@ -368,8 +367,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
details.append("prefix=").append(annotation.prefix());
details.append(", ignoreInvalidFields=").append(annotation.ignoreInvalidFields());
details.append(", ignoreUnknownFields=").append(annotation.ignoreUnknownFields());
details.append(", ignoreNestedProperties=")
.append(annotation.ignoreNestedProperties());
return details.toString();
}
@ -413,11 +410,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
handler = new IgnoreErrorsBindHandler(handler);
}
if (!annotation.ignoreUnknownFields()) {
handler = new NoUnboundElementsBindHandler(handler,
annotation.ignoreNestedProperties());
}
if (annotation.ignoreNestedProperties()) {
handler = new IgnoreNestedPropertiesBindHandler(handler);
handler = new NoUnboundElementsBindHandler(handler);
}
if (validator != null) {
handler = new ValidationBindHandler(handler, validator);

@ -40,28 +40,14 @@ import org.springframework.boot.context.properties.source.IterableConfigurationP
*/
public class NoUnboundElementsBindHandler extends AbstractBindHandler {
private final boolean ignoreNested;
private final Set<ConfigurationPropertyName> boundNames = new HashSet<>();
public NoUnboundElementsBindHandler() {
super();
this.ignoreNested = false;
}
public NoUnboundElementsBindHandler(boolean ignoreNested) {
NoUnboundElementsBindHandler() {
super();
this.ignoreNested = ignoreNested;
}
public NoUnboundElementsBindHandler(BindHandler parent) {
super(parent);
this.ignoreNested = false;
}
public NoUnboundElementsBindHandler(BindHandler parent, boolean ignoreNested) {
super(parent);
this.ignoreNested = ignoreNested;
}
@Override
@ -110,11 +96,7 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
private boolean isUnbound(ConfigurationPropertyName name,
ConfigurationPropertyName candidate) {
boolean isParent = candidate.getParent() != null
&& name.equals(candidate.getParent());
boolean isAncestor = name.isAncestorOf(candidate);
return ((this.ignoreNested ? isParent : isAncestor)
&& !this.boundNames.contains(candidate));
return name.isAncestorOf(candidate) && !this.boundNames.contains(candidate);
}
}

@ -118,18 +118,6 @@ public class EnableConfigurationPropertiesTests {
assertThat(this.context.getBean(TestProperties.class).name).isEqualTo("foo");
}
@Test
public void testIgnoreNestedPropertiesBinding() {
removeSystemProperties();
this.context.register(IgnoreNestedTestConfiguration.class);
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"name=foo", "nested.name=bar");
this.context.refresh();
assertThat(this.context.getBeanNamesForType(IgnoreNestedTestProperties.class))
.hasSize(1);
assertThat(this.context.getBean(TestProperties.class).name).isEqualTo("foo");
}
@Test
public void testExceptionOnValidation() {
this.context.register(ExceptionIfInvalidTestConfiguration.class);
@ -380,12 +368,6 @@ public class EnableConfigurationPropertiesTests {
}
@Configuration
@EnableConfigurationProperties(IgnoreNestedTestProperties.class)
protected static class IgnoreNestedTestConfiguration {
}
@Configuration
@EnableConfigurationProperties(ExceptionIfInvalidTestProperties.class)
protected static class ExceptionIfInvalidTestConfiguration {
@ -616,11 +598,6 @@ public class EnableConfigurationPropertiesTests {
}
@ConfigurationProperties(ignoreUnknownFields = false, ignoreNestedProperties = true)
protected static class IgnoreNestedTestProperties extends TestProperties {
}
@ConfigurationProperties
@Validated
protected static class ExceptionIfInvalidTestProperties extends TestProperties {

@ -103,37 +103,6 @@ public class NoUnboundElementsBindHandlerTests {
assertThat(bound.getFoo()).isEqualTo("bar");
}
@Test
public void bindWhenUsingNoUnboundElementsHandlerIgnoreNestedAndUnboundChildShouldThrowException()
throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("example.baz", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
try {
this.binder.bind("example", Bindable.of(Example.class),
new NoUnboundElementsBindHandler(true));
fail("did not throw");
}
catch (BindException ex) {
assertThat(ex.getCause().getMessage())
.contains("The elements [example.baz] were left unbound");
}
}
@Test
public void bindWhenUsingNoUnboundElementsHandlerIgnoreNestedAndUnboundGrandchildShouldBind()
throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("example.foo.baz", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
this.binder.bind("example", Bindable.of(Example.class),
new NoUnboundElementsBindHandler(true));
}
public static class Example {
private String foo;

Loading…
Cancel
Save