Browse Source

Change binding exceptionIfInvalid default to true

Issue: #54462302
pull/9/head
Phillip Webb 13 years ago
parent
commit
6ada4553ae
  1. 13
      spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java
  2. 1
      spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java
  3. 4
      spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java

13
spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java

@ -51,9 +51,9 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>, @@ -51,9 +51,9 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
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<T> implements FactoryBean<T>, @@ -196,13 +196,15 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
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<T> implements FactoryBean<T>, @@ -246,8 +248,7 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
: error);
}
if (this.exceptionIfInvalid) {
BindException summary = new BindException(errors);
throw summary;
throw new BindException(errors);
}
}
}

1
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java

@ -271,7 +271,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc @@ -271,7 +271,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(
target);
if (annotation != null && annotation.path().length != 0) {
factory.setPropertySources(loadPropertySources(annotation.path()));
}
else {

4
spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java

@ -21,7 +21,6 @@ import javax.validation.constraints.NotNull; @@ -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 { @@ -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 { @@ -99,7 +96,6 @@ public class PropertiesConfigurationFactoryTests {
this.factory = new PropertiesConfigurationFactory<Foo>(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);

Loading…
Cancel
Save