Commit 0286128b authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 393cfe50
...@@ -186,7 +186,10 @@ public class PropertiesConfigurationFactory<T> ...@@ -186,7 +186,10 @@ public class PropertiesConfigurationFactory<T>
* Set a flag to indicate that an exception should be raised if a Validator is * Set a flag to indicate that an exception should be raised if a Validator is
* available and validation fails. * available and validation fails.
* @param exceptionIfInvalid the flag to set * @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) { public void setExceptionIfInvalid(boolean exceptionIfInvalid) {
this.exceptionIfInvalid = exceptionIfInvalid; this.exceptionIfInvalid = exceptionIfInvalid;
} }
......
...@@ -86,7 +86,10 @@ public @interface ConfigurationProperties { ...@@ -86,7 +86,10 @@ public @interface ConfigurationProperties {
* it is set to false, validation errors will be swallowed. They will be logged, but * it is set to false, validation errors will be swallowed. They will be logged, but
* not propagated to the caller. * not propagated to the caller.
* @return the flag value (default true) * @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; boolean exceptionIfInvalid() default true;
} }
...@@ -304,6 +304,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc ...@@ -304,6 +304,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
return bean; return bean;
} }
@SuppressWarnings("deprecation")
private void postProcessBeforeInitialization(Object bean, String beanName, private void postProcessBeforeInitialization(Object bean, String beanName,
ConfigurationProperties annotation) { ConfigurationProperties annotation) {
Object target = bean; Object target = bean;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -84,6 +84,7 @@ public class PropertiesConfigurationFactoryTests { ...@@ -84,6 +84,7 @@ public class PropertiesConfigurationFactoryTests {
} }
@Test @Test
@Deprecated
public void testValidationErrorCanBeSuppressed() throws Exception { public void testValidationErrorCanBeSuppressed() throws Exception {
this.validator = new SpringValidatorAdapter( this.validator = new SpringValidatorAdapter(
Validation.buildDefaultValidatorFactory().getValidator()); Validation.buildDefaultValidatorFactory().getValidator());
......
...@@ -185,6 +185,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -185,6 +185,7 @@ public class EnableConfigurationPropertiesTests {
} }
@Test @Test
@Deprecated
public void testNoExceptionOnValidation() { public void testNoExceptionOnValidation() {
this.context.register(NoExceptionIfInvalidTestConfiguration.class); this.context.register(NoExceptionIfInvalidTestConfiguration.class);
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
...@@ -452,6 +453,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -452,6 +453,7 @@ public class EnableConfigurationPropertiesTests {
@Configuration @Configuration
@EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class) @EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class)
@Deprecated
protected static class NoExceptionIfInvalidTestConfiguration { protected static class NoExceptionIfInvalidTestConfiguration {
} }
...@@ -711,6 +713,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -711,6 +713,7 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(exceptionIfInvalid = false) @ConfigurationProperties(exceptionIfInvalid = false)
@Validated @Validated
@Deprecated
protected static class NoExceptionIfInvalidTestProperties extends TestProperties { protected static class NoExceptionIfInvalidTestProperties extends TestProperties {
@NotNull @NotNull
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment