I am getting "Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath." this error when try to implement the Validation for my Entity (ProductInstance)
Here is the Usage
try {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
for (ConstraintViolation<ProductInstance> violation : validator.validate(product)) {
genActResponse.addErrorMessage(violation.getMessage());
genActResponse.addFailure();
return genActResponse;
}
} catch (Exception e) {
throw e;
}
Here is the Dependency in gradle.build
dependencies {
compile group: 'org.hibernate', name: 'hibernate-validator-annotation-processor', version: '6.0.2.Final'
And here is the error I am getting
2018-12-03 20:22:12,420 WebErrorHandler ERROR - General exception
javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:291)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:103)
at com.helpsystems.incn.access.service.DefaultProductInstanceService.updateProduct(DefaultProductInstanceService.java:200)
at com.helpsystems.incn.server.ProductInstanceController.updateProduct(ProductInstanceController.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Note that since Hibernate 5, Hibernate deprecated several of its specific validation constraint classes in favor to standard JSR 380-bean validation classes. Note also that the Hibernate Validator 6 library is actually the reference implementation of this JSR.
Hibernate Validator allows to express and validate application constraints. The default metadata source are annotations, with the ability to override and extend through the use of XML. It is not tied to a specific application tier or programming model and is available for both server and client application programming.
In the setUp() method, a Validator instance is retrieved from the ValidatorFactory . Validator instances are thread-safe and may be reused multiple times.
Hibernate Validator Annotation Processor It helps to detect glitches such as: Putting a constraint to bean properties which are not supported by that constraint (e.g. putting @Date to a String) Annotating the setter of a bean property instead of the getter. Adding constraints to static fields or methods.
You need to add Hibernate validator. Add one of the following:
For Gradle, add:
compile group: 'org.hibernate', name: 'hibernate-validator', version: '6.0.13.Final'
For Maven, add:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
You can adjust the version based on other dependencies versions'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With