diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java index 9c3f7da6e53..4faec765109 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java @@ -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. diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java index ca59446eb50..2c3db47a9d2 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java @@ -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); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java index 6014150d92c..162464a51a5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java @@ -40,28 +40,14 @@ import org.springframework.boot.context.properties.source.IterableConfigurationP */ public class NoUnboundElementsBindHandler extends AbstractBindHandler { - private final boolean ignoreNested; - private final Set 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); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index 504aec76d35..b47ec7ded27 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -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 { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandlerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandlerTests.java index 0f70ce5eaf6..0733005839d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandlerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandlerTests.java @@ -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;