Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting NoProviderFoundException When try to implement "Hibernate Validator"

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)
like image 437
Vahram Davoyan Avatar asked Dec 03 '18 16:12

Vahram Davoyan


People also ask

Is Hibernate Validator deprecated?

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.

How does Hibernate Validator work?

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.

Is Hibernate Validator thread-safe?

In the setUp() method, a Validator instance is retrieved from the ValidatorFactory . Validator instances are thread-safe and may be reused multiple times.

What is Hibernate Validator annotation processor?

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.


1 Answers

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'

like image 62
Zeusox Avatar answered Oct 22 '22 10:10

Zeusox