Make @Validated a hard requirement for JSR-303 validation
Closes gh-8024
This commit is contained in:
parent
97c1365e24
commit
3412ee62d5
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.context.properties;
|
package org.springframework.boot.context.properties;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import org.springframework.boot.validation.MessageInterpolatorFactory;
|
import org.springframework.boot.validation.MessageInterpolatorFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
|
@ -33,9 +30,6 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||||
*/
|
*/
|
||||||
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
||||||
|
|
||||||
private static final Log logger = LogFactory
|
|
||||||
.getLog(ConfigurationPropertiesBindingPostProcessor.class);
|
|
||||||
|
|
||||||
ValidatedLocalValidatorFactoryBean(ApplicationContext applicationContext) {
|
ValidatedLocalValidatorFactoryBean(ApplicationContext applicationContext) {
|
||||||
setApplicationContext(applicationContext);
|
setApplicationContext(applicationContext);
|
||||||
setMessageInterpolator(new MessageInterpolatorFactory().getObject());
|
setMessageInterpolator(new MessageInterpolatorFactory().getObject());
|
||||||
|
@ -44,22 +38,8 @@ class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> type) {
|
public boolean supports(Class<?> type) {
|
||||||
if (!super.supports(type)) {
|
return super.supports(type)
|
||||||
return false;
|
&& AnnotatedElementUtils.hasAnnotation(type, Validated.class);
|
||||||
}
|
|
||||||
if (AnnotatedElementUtils.hasAnnotation(type, Validated.class)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (type.getPackage() != null
|
|
||||||
&& type.getPackage().getName().startsWith("org.springframework.boot")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getConstraintsForClass(type).isBeanConstrained()) {
|
|
||||||
logger.warn("The @ConfigurationProperties bean " + type
|
|
||||||
+ " contains validation constraints but had not been annotated "
|
|
||||||
+ "with @Validated.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue