Change binding exceptionIfInvalid default to true

Issue: #54462302
This commit is contained in:
Phillip Webb 2013-08-01 10:59:25 -07:00
parent 88bc6c0b56
commit 6ada4553ae
3 changed files with 7 additions and 11 deletions

View File

@ -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>,
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>,
: error);
}
if (this.exceptionIfInvalid) {
BindException summary = new BindException(errors);
throw summary;
throw new BindException(errors);
}
}
}

View File

@ -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 {

View File

@ -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>(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);