Initial support for Bean Validation 1.1 and Hibernate Validator 5.0
MethodValidationInterceptor autodetects Bean Validation 1.1's ExecutableValidator API now and uses it in favor of Hibernate Validator 4.2's native variant. SpringConstraintValidatorFactory implements Bean Validation 1.1 "releaseInstance" method against new "destroyBean(Object)" method in AutowireCapableBeanFactory. LocalValidatorFactoryBean adapts Spring-provided ParameterNameDiscoverer onto Bean Validation 1.1's ParameterNameProvider mechanism. LocalValidatorFactoryBean reflectively adapts between the different ResourceBundleLocator SPI location in Hibernate Validator 4.2 versus 5.0. LocalValidatorFactoryBean implements Bean Validation 1.1 "close" method. Note: We still compile against Bean Validation 1.0 in order to not have to implement "forExecutables()" and "getParameterNameDiscoverer()" in LocalValidatorFactoryBean, SpringValidatorAdapter and CustomValidatorBean. Implementing those methods would imply references to Bean Validation 1.1 interfaces that break runtime compatibility with Bean Validation 1.0. Unfortunately, this means that all Bean Validation 1.1 API access has to be done via reflection. Issue: SPR-8199
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,6 @@ import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
import org.hibernate.validator.method.MethodConstraintViolationException;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
@@ -61,21 +60,21 @@ public class MethodValidationTests {
|
||||
assertNotNull(proxy.myValidMethod("value", 15));
|
||||
fail("Should have thrown MethodConstraintViolationException");
|
||||
}
|
||||
catch (MethodConstraintViolationException ex) {
|
||||
catch (javax.validation.ValidationException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
assertNotNull(proxy.myValidMethod(null, 5));
|
||||
fail("Should have thrown MethodConstraintViolationException");
|
||||
}
|
||||
catch (MethodConstraintViolationException ex) {
|
||||
catch (javax.validation.ValidationException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
assertNotNull(proxy.myValidMethod("value", 0));
|
||||
fail("Should have thrown MethodConstraintViolationException");
|
||||
}
|
||||
catch (MethodConstraintViolationException ex) {
|
||||
catch (javax.validation.ValidationException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user