mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Prevent warning due to BPP dependency
`MethodValidationPostProcessor` requires a `Validator` so we need to flag it as an infrastructure bean to prevent an additional log that indicates it won't be post-processed. We obviously don't want to post-process the `Validator` here so adding the additional meta-data is a good idea anyway. Closes gh-8422
This commit is contained in:
parent
f032d2fe03
commit
d8f62c46ad
@ -19,12 +19,15 @@ package org.springframework.boot.autoconfigure.validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.executable.ExecutableValidator;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
|
||||
import org.springframework.boot.validation.MessageInterpolatorFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
|
||||
@ -35,13 +38,15 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(ExecutableValidator.class)
|
||||
@ConditionalOnResource(resources = "classpath:META-INF/services/javax.validation.spi.ValidationProvider")
|
||||
public class ValidationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnMissingBean
|
||||
public Validator validator() {
|
||||
public static Validator validator() {
|
||||
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
||||
MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory();
|
||||
factoryBean.setMessageInterpolator(interpolatorFactory.getObject());
|
||||
@ -50,7 +55,7 @@ public class ValidationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MethodValidationPostProcessor methodValidationPostProcessor(
|
||||
public static MethodValidationPostProcessor methodValidationPostProcessor(
|
||||
Validator validator) {
|
||||
MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
|
||||
processor.setProxyTargetClass(true);
|
||||
|
Loading…
Reference in New Issue
Block a user