Skip to content

Commit f5445ba

Browse files
committed
Remove OnValidatorAvailableCondition as it is now redundant
Previously, Hibernate Validator would fail to initialize if it was on the classpath but an EL implementation was not. OnValidatorAvailableCondition protected against this scenario by initializing the validator. The Hibernate Validator shortcoming was addressed in eb22220 (gh-7598). As a result, checking for the precences of the ValidationProvider META-INF/services resource is now sufficient to auto-configure validation. This commit removes OnValidatorAvailableCondition as it is no longer necessary. Closes gh-8110
1 parent 6b353fb commit f5445ba

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,24 +16,15 @@
1616

1717
package org.springframework.boot.autoconfigure.validation;
1818

19-
import javax.validation.Validation;
2019
import javax.validation.Validator;
2120
import javax.validation.executable.ExecutableValidator;
2221

2322
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
24-
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
25-
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
2623
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2724
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2825
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
29-
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
3026
import org.springframework.boot.validation.MessageInterpolatorFactory;
3127
import org.springframework.context.annotation.Bean;
32-
import org.springframework.context.annotation.ConditionContext;
33-
import org.springframework.context.annotation.Conditional;
34-
import org.springframework.core.Ordered;
35-
import org.springframework.core.annotation.Order;
36-
import org.springframework.core.type.AnnotatedTypeMetadata;
3728
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
3829
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
3930

@@ -46,7 +37,6 @@
4637
*/
4738
@ConditionalOnClass(ExecutableValidator.class)
4839
@ConditionalOnResource(resources = "classpath:META-INF/services/javax.validation.spi.ValidationProvider")
49-
@Conditional(ValidationAutoConfiguration.OnValidatorAvailableCondition.class)
5040
public class ValidationAutoConfiguration {
5141

5242
@Bean
@@ -67,23 +57,4 @@ public MethodValidationPostProcessor methodValidationPostProcessor(
6757
return processor;
6858
}
6959

70-
@Order(Ordered.LOWEST_PRECEDENCE)
71-
static class OnValidatorAvailableCondition extends SpringBootCondition {
72-
73-
@Override
74-
public ConditionOutcome getMatchOutcome(ConditionContext context,
75-
AnnotatedTypeMetadata metadata) {
76-
ConditionMessage.Builder message = ConditionMessage
77-
.forCondition(getClass().getName());
78-
try {
79-
Validation.buildDefaultValidatorFactory().getValidator();
80-
return ConditionOutcome.match(message.available("JSR-303 provider"));
81-
}
82-
catch (Exception ex) {
83-
return ConditionOutcome.noMatch(message.notAvailable("JSR-303 provider"));
84-
}
85-
}
86-
87-
}
88-
8960
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationWithHibernateValidatorMissingElImplTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,12 +49,12 @@ public void close() {
4949
}
5050

5151
@Test
52-
public void validationIsDisabled() {
52+
public void missingElDependencyIsTolerated() {
5353
this.context = new AnnotationConfigApplicationContext(
5454
ValidationAutoConfiguration.class);
55-
assertThat(this.context.getBeansOfType(Validator.class)).isEmpty();
55+
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
5656
assertThat(this.context.getBeansOfType(MethodValidationPostProcessor.class))
57-
.isEmpty();
57+
.hasSize(1);
5858
}
5959

6060
}

0 commit comments

Comments
 (0)