parent
88bc6c0b56
commit
6ada4553ae
|
|
@ -51,9 +51,9 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||||
|
|
||||||
private boolean ignoreUnknownFields = true;
|
private boolean ignoreUnknownFields = true;
|
||||||
|
|
||||||
private boolean ignoreInvalidFields = false;
|
private boolean ignoreInvalidFields;
|
||||||
|
|
||||||
private boolean exceptionIfInvalid;
|
private boolean exceptionIfInvalid = true;
|
||||||
|
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
|
|
@ -196,13 +196,15 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||||
if (this.logger.isTraceEnabled()) {
|
if (this.logger.isTraceEnabled()) {
|
||||||
if (this.properties != null) {
|
if (this.properties != null) {
|
||||||
this.logger.trace("Properties:\n" + this.properties);
|
this.logger.trace("Properties:\n" + this.properties);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.logger.trace("Property Sources: " + this.propertySources);
|
this.logger.trace("Property Sources: " + this.propertySources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.hasBeenBound = true;
|
this.hasBeenBound = true;
|
||||||
doBindPropertiesToTarget();
|
doBindPropertiesToTarget();
|
||||||
} catch (BindException ex) {
|
}
|
||||||
|
catch (BindException ex) {
|
||||||
if (this.exceptionIfInvalid) {
|
if (this.exceptionIfInvalid) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
@ -246,8 +248,7 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||||
: error);
|
: error);
|
||||||
}
|
}
|
||||||
if (this.exceptionIfInvalid) {
|
if (this.exceptionIfInvalid) {
|
||||||
BindException summary = new BindException(errors);
|
throw new BindException(errors);
|
||||||
throw summary;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
|
||||||
PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(
|
PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(
|
||||||
target);
|
target);
|
||||||
if (annotation != null && annotation.path().length != 0) {
|
if (annotation != null && annotation.path().length != 0) {
|
||||||
|
|
||||||
factory.setPropertySources(loadPropertySources(annotation.path()));
|
factory.setPropertySources(loadPropertySources(annotation.path()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.NotWritablePropertyException;
|
import org.springframework.beans.NotWritablePropertyException;
|
||||||
import org.springframework.boot.bind.PropertiesConfigurationFactory;
|
|
||||||
import org.springframework.context.support.StaticMessageSource;
|
import org.springframework.context.support.StaticMessageSource;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||||
|
|
@ -42,8 +41,6 @@ public class PropertiesConfigurationFactoryTests {
|
||||||
|
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
private boolean exceptionIfInvalid = true;
|
|
||||||
|
|
||||||
private boolean ignoreUnknownFields = true;
|
private boolean ignoreUnknownFields = true;
|
||||||
|
|
||||||
private String targetName = null;
|
private String targetName = null;
|
||||||
|
|
@ -99,7 +96,6 @@ public class PropertiesConfigurationFactoryTests {
|
||||||
this.factory = new PropertiesConfigurationFactory<Foo>(Foo.class);
|
this.factory = new PropertiesConfigurationFactory<Foo>(Foo.class);
|
||||||
this.factory.setProperties(PropertiesLoaderUtils
|
this.factory.setProperties(PropertiesLoaderUtils
|
||||||
.loadProperties(new ByteArrayResource(values.getBytes())));
|
.loadProperties(new ByteArrayResource(values.getBytes())));
|
||||||
this.factory.setExceptionIfInvalid(this.exceptionIfInvalid);
|
|
||||||
this.factory.setValidator(this.validator);
|
this.factory.setValidator(this.validator);
|
||||||
this.factory.setTargetName(this.targetName);
|
this.factory.setTargetName(this.targetName);
|
||||||
this.factory.setIgnoreUnknownFields(this.ignoreUnknownFields);
|
this.factory.setIgnoreUnknownFields(this.ignoreUnknownFields);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue