mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.validation.MessageInterpolatorFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
@ -33,9 +30,6 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
*/
|
||||
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(ConfigurationPropertiesBindingPostProcessor.class);
|
||||
|
||||
ValidatedLocalValidatorFactoryBean(ApplicationContext applicationContext) {
|
||||
setApplicationContext(applicationContext);
|
||||
setMessageInterpolator(new MessageInterpolatorFactory().getObject());
|
||||
@ -44,22 +38,8 @@ class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
if (!super.supports(type)) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
return super.supports(type)
|
||||
&& AnnotatedElementUtils.hasAnnotation(type, Validated.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user