Revert "Stop auto-config of MethodValidationPP triggering early init"
5198fe887b
. The underlying Framework
problem that prevents @Lazy from working properly is still there
in some form or another.
See gh-9416
This commit is contained in:
parent
5198fe887b
commit
15410a406e
|
@ -29,7 +29,6 @@ import org.springframework.boot.validation.MessageInterpolatorFactory;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
@ -61,7 +60,7 @@ public class ValidationAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public static MethodValidationPostProcessor methodValidationPostProcessor(
|
||||
Environment environment, @Lazy Validator validator) {
|
||||
Environment environment, Validator validator) {
|
||||
MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
|
||||
processor.setProxyTargetClass(determineProxyTargetClass(environment));
|
||||
processor.setValidator(validator);
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.validation;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.constraints.Min;
|
||||
|
@ -30,15 +27,12 @@ import org.junit.Test;
|
|||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigurationTests.CustomValidatorConfiguration.TestBeanPostProcessor;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.validation.beanvalidation.CustomValidatorBean;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
|
||||
|
@ -204,13 +198,6 @@ public class ValidationAutoConfigurationTests {
|
|||
.getPropertyValue("validator"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodValidationPostProcessorValidatorDependencyDoesNotTriggerEarlyInitialization() {
|
||||
load(CustomValidatorConfiguration.class);
|
||||
assertThat(this.context.getBean(TestBeanPostProcessor.class).postProcessed)
|
||||
.contains("someService");
|
||||
}
|
||||
|
||||
private boolean isPrimaryBean(String beanName) {
|
||||
return this.context.getBeanDefinition(beanName).isPrimary();
|
||||
}
|
||||
|
@ -335,53 +322,4 @@ public class ValidationAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomValidatorConfiguration {
|
||||
|
||||
CustomValidatorConfiguration(SomeService someService) {
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
Validator customValidator() {
|
||||
return new CustomValidatorBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
static TestBeanPostProcessor testBeanPostProcessor() {
|
||||
return new TestBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class SomeServiceConfiguration {
|
||||
|
||||
@Bean
|
||||
public SomeService someService() {
|
||||
return new SomeService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class SomeService {
|
||||
|
||||
}
|
||||
|
||||
static class TestBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private Set<String> postProcessed = new HashSet<String>();
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String name) {
|
||||
this.postProcessed.add(name);
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue