Deprecate exceptionIfInvalid

This commit deprecates the `exceptionIfInvalid` feature as we have now a
way to select the `@ConfigurationProperties` object to validate (i.e. add
`@Validated` on them).

Closes gh-8027
This commit is contained in:
Stephane Nicoll
2017-01-23 13:29:26 +01:00
parent 393cfe505e
commit 0286128b28
5 changed files with 12 additions and 1 deletions

View File

@@ -186,7 +186,10 @@ public class PropertiesConfigurationFactory<T>
* Set a flag to indicate that an exception should be raised if a Validator is
* available and validation fails.
* @param exceptionIfInvalid the flag to set
* @deprecated as of 1.5, do not specify a {@link Validator} if validation should not
* occur
*/
@Deprecated
public void setExceptionIfInvalid(boolean exceptionIfInvalid) {
this.exceptionIfInvalid = exceptionIfInvalid;
}

View File

@@ -86,7 +86,10 @@ public @interface ConfigurationProperties {
* it is set to false, validation errors will be swallowed. They will be logged, but
* not propagated to the caller.
* @return the flag value (default true)
* @deprecated as of 1.5 since validation only kicks in when {@code @Validated} is
* present
*/
@Deprecated
boolean exceptionIfInvalid() default true;
}

View File

@@ -304,6 +304,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
return bean;
}
@SuppressWarnings("deprecation")
private void postProcessBeforeInitialization(Object bean, String beanName,
ConfigurationProperties annotation) {
Object target = bean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,6 +84,7 @@ public class PropertiesConfigurationFactoryTests {
}
@Test
@Deprecated
public void testValidationErrorCanBeSuppressed() throws Exception {
this.validator = new SpringValidatorAdapter(
Validation.buildDefaultValidatorFactory().getValidator());

View File

@@ -185,6 +185,7 @@ public class EnableConfigurationPropertiesTests {
}
@Test
@Deprecated
public void testNoExceptionOnValidation() {
this.context.register(NoExceptionIfInvalidTestConfiguration.class);
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
@@ -452,6 +453,7 @@ public class EnableConfigurationPropertiesTests {
@Configuration
@EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class)
@Deprecated
protected static class NoExceptionIfInvalidTestConfiguration {
}
@@ -711,6 +713,7 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(exceptionIfInvalid = false)
@Validated
@Deprecated
protected static class NoExceptionIfInvalidTestProperties extends TestProperties {
@NotNull