commit
8ff2b9f2e8
|
@ -72,6 +72,15 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
|
|||
return super.onSuccess(name, target, context, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error)
|
||||
throws Exception {
|
||||
if (error instanceof UnboundConfigurationPropertiesException) {
|
||||
throw error;
|
||||
}
|
||||
return super.onFailure(name, target, context, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
|
||||
throws Exception {
|
||||
|
|
|
@ -170,6 +170,14 @@ class ConfigurationPropertiesTests {
|
|||
.withCauseInstanceOf(BindException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenIgnoreUnknownFieldsFalseAndIgnoreInvalidFieldsTrueWhenThereAreUnknownFieldsThenBindingShouldFail() {
|
||||
removeSystemProperties();
|
||||
assertThatExceptionOfType(ConfigurationPropertiesBindException.class).isThrownBy(
|
||||
() -> load(IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueConfiguration.class, "name=foo", "bar=baz"))
|
||||
.withCauseInstanceOf(BindException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadWhenHasIgnoreInvalidFieldsTrueAndInvalidFieldsShouldBind() {
|
||||
load(IgnoreInvalidFieldsFalseProperties.class, "com.example.bar=spam");
|
||||
|
@ -969,6 +977,12 @@ class ConfigurationPropertiesTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueProperties.class)
|
||||
static class IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(PrefixProperties.class)
|
||||
static class PrefixConfiguration {
|
||||
|
@ -1416,6 +1430,11 @@ class ConfigurationPropertiesTests {
|
|||
|
||||
}
|
||||
|
||||
@ConfigurationProperties(ignoreUnknownFields = false, ignoreInvalidFields = true)
|
||||
static class IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueProperties extends BasicProperties {
|
||||
|
||||
}
|
||||
|
||||
@EnableConfigurationProperties
|
||||
@ConfigurationProperties(prefix = "com.example", ignoreInvalidFields = true)
|
||||
static class IgnoreInvalidFieldsFalseProperties {
|
||||
|
|
Loading…
Reference in New Issue