@Configuration
@ConditionalOnClass(ExecutableValidator.class)
@ConditionalOnResource(resources = "classpath:META-INF/services/javax.validation.spi.ValidationProvider")
@Import(PrimaryDefaultValidatorPostProcessor.class)
public class ValidationAutoConfiguration {
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConditionalOnMissingBean(Validator.class)
public static LocalValidatorFactoryBean defaultValidator() {
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory();
factoryBean.setMessageInterpolator(interpolatorFactory.getObject());
return factoryBean;
}
@Bean
@ConditionalOnMissingBean
public static MethodValidationPostProcessor methodValidationPostProcessor(
Environment environment, Validator validator) {
MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
processor.setProxyTargetClass(determineProxyTargetClass(environment));
processor.setValidator(validator);
return processor;
}
private static boolean determineProxyTargetClass(Environment environment) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"spring.aop.");
Boolean value = resolver.getProperty("proxyTargetClass", Boolean.class);
return (value != null ? value : true);
}
}
这个注解类会根据是否存在ExecutableValidator类和ValidationProvider文件确定是否注入,ValidationProvider文件在hibernate-validator 的jar包配置里。正常情况下引入spring-boot-strater后 会引入ExecutableValidator类,和hibernate-validator包。这就导致debug开启时一直会爆
trationDelegate$BeanPostProcessorChecker : Bean 'popNotifyServiceFacade' of type [com.alibaba.dubbo.config.spring.ReferenceBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
这种错误。解决方案有两种,1.踢掉validation的依赖,2.踢掉hibernate-validation的依赖。