I'm using the Validation class in a Thread that has the context class loader set to a class loader that will not find the JAR file containing the Validation class. When calling
Validation.buildDefaultValidatorFactory();
in this environment, it results in a ValidationException being throw from GenericBootstrapImpl.configure with the message "Unable to find a default provider".
The reason for this is that DefaultValidationProviderResolver.getValidationProviders uses the thread context class loader to get the "META-INF/services/javax.validation.Validation" resource, but if it isn't there (which is the case in my environment), it doesn't try to use the class loader for the DefaultValidationProviderResolver class.
A workaround for this issue is to set the context class loader to null before calling the buildDefaultValidatorFactory method.
|