diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java index c32f47262b2..806e580eae4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java @@ -51,9 +51,9 @@ public class PropertiesConfigurationFactory implements FactoryBean, private boolean ignoreUnknownFields = true; - private boolean ignoreInvalidFields = false; + private boolean ignoreInvalidFields; - private boolean exceptionIfInvalid; + private boolean exceptionIfInvalid = true; private Properties properties; @@ -196,13 +196,15 @@ public class PropertiesConfigurationFactory implements FactoryBean, if (this.logger.isTraceEnabled()) { if (this.properties != null) { this.logger.trace("Properties:\n" + this.properties); - } else { + } + else { this.logger.trace("Property Sources: " + this.propertySources); } } this.hasBeenBound = true; doBindPropertiesToTarget(); - } catch (BindException ex) { + } + catch (BindException ex) { if (this.exceptionIfInvalid) { throw ex; } @@ -246,8 +248,7 @@ public class PropertiesConfigurationFactory implements FactoryBean, : error); } if (this.exceptionIfInvalid) { - BindException summary = new BindException(errors); - throw summary; + throw new BindException(errors); } } } 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 32a36285a55..c6ce051d0c5 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 @@ -271,7 +271,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory( target); if (annotation != null && annotation.path().length != 0) { - factory.setPropertySources(loadPropertySources(annotation.path())); } else { diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java index 658d69b691c..e894671441e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java @@ -21,7 +21,6 @@ import javax.validation.constraints.NotNull; import org.junit.Test; import org.springframework.beans.NotWritablePropertyException; -import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.context.support.StaticMessageSource; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.support.PropertiesLoaderUtils; @@ -42,8 +41,6 @@ public class PropertiesConfigurationFactoryTests { private Validator validator; - private boolean exceptionIfInvalid = true; - private boolean ignoreUnknownFields = true; private String targetName = null; @@ -99,7 +96,6 @@ public class PropertiesConfigurationFactoryTests { this.factory = new PropertiesConfigurationFactory(Foo.class); this.factory.setProperties(PropertiesLoaderUtils .loadProperties(new ByteArrayResource(values.getBytes()))); - this.factory.setExceptionIfInvalid(this.exceptionIfInvalid); this.factory.setValidator(this.validator); this.factory.setTargetName(this.targetName); this.factory.setIgnoreUnknownFields(this.ignoreUnknownFields);