javax.validation.ValidationException: Unable to find default provider

后端 未结 6 1454
天涯浪人
天涯浪人 2020-12-14 01:33

I am currently working on Spring MVC web app and trying to hook up validation using the @Valid annotation. When I fire up the application I\'m getting the following exceptio

相关标签:
6条回答
  • 2020-12-14 01:45

    I received the following error:

    Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to get available provider resolvers

    I discovered that in my WEB-INF/lib directory I had two versions of Validator.class present in both of the following jar files:

    • org.springframework.context-3.1.1.RELEASE.jar
    • com.springsource.javax.validation-1.0.0.GA.jar

    I removed the com.springsource.javax.validation-1.0.0.GA.jar from the WEB-INF/lib directory because it is older and no longer supported. After doing so, my application worked perfectly. I learned from other posts that my problem had something to do with duplicate versions of the same file on the classpath. I figured out which file was causing the problem after reading Spring 3 Validation

    0 讨论(0)
  • 2020-12-14 01:50

    See this answer : https://stackoverflow.com/a/3989936/325742

    To fix, Add this maven dependency Hibernate Validator Annotation Processor.

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator-annotation-processor</artifactId>
      <version>4.1.0.Final</version>
    </dependency>
    

    That's the latest stable version of that artifact, as seen from here


    Generic way of finding a dependency

    Let's say that you got a a NoClassDefFoundError stating that the class org.postgresql.Driver was not found.

    1. Use Jarvana to search for a dependency that can provide org.postgresql.Driver like so : http://www.jarvana.com/jarvana/search?search_type=class&java_class=org.postgresql.Driver which gives enter image description here

    2. Translate the above dependency into maven dependency format :

      <dependency>
          <groupId>postgresql</groupId>
         <artifactId>postgresql</artifactId>
         <version>9.1-901.jdbc4</version>
       </dependency>
      
    3. Confirm that the above is available at Maven Central by searching like this :
      g:"postgresql" AND a:"postgresql"
      (where g stands for GroupID and a stands for artifactID)

    4. Finally, add it to your pom.xml


    Finding Dependencies using m2e

    If you have an approximate idea of the dependency needed or can figure out the one you need given a list, then m2e's dependency search can be the quickest way of adding a dependency to your pom.xml

    Steps :

    1. Click on the Dependencies tab (A) in your pom.xml
    2. Click on Add (B)
    3. Search for the dependency by groupId/artifactId (C)
    4. Double click the required one from the search results to have it added directly to your pom.xml (D)

    A-D marked in the following snapshot : enter image description here


    Finding dependencies in IntelliJ Idea

    In IntelliJ, looking up a dependency is much easier. All you need to do, is to make sure that the maven central repo has been indexed by IntelliJ like so:

    enter image description here

    And then, go into the pom, do a dep+Tab (or an Alt+Insert as shown here), and this is what you get: enter image description here

    If you are in a class which has an unresolved import, then the quick fix gives you an option of searching and adding the corresponding maven repo by doing an Alt+Enter on the missing Class/Package: enter image description here

    Awesome I say !


    0 讨论(0)
  • 2020-12-14 01:51

    This happened to me without Hibernate.

    Running great on my PC, it didn't work on my EC2 Linux server.

    The reason was an existence of validation-api-1.0.0.GA.jar file under /usr/share/tomcat/lib.

    Once validation-api-1.0.0.GA.jar deleted, it worked great.

    0 讨论(0)
  • 2020-12-14 01:53

    In my case, I had the same problem, but it was happening because the jar of hibernate-core version 4.1.8.Final downloaded by maven was corrupted. I swithed to version 4.1.6.Final and it started working. I was using STS and spring repositories.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-14 02:05

    Hibernate Validator 3.1 is not a JSR303 provider. You need to upgrade to Hibernate Validator 4 or later.

    0 讨论(0)
  • 2020-12-14 02:07

    In same Situation i update my Jar version only for anotations from hibernate-anotation and hibernate-common-annotation to Hibernate4 anotations which are listed below. For Hibernate 4 you can use this jars-

    1-hibernate-commons-annotations-4.0.5.Final 2-hibernate-validator-4.2.0.Final

    Hope this will work for you also.

    0 讨论(0)
提交回复
热议问题