简体   繁体   English

javax.validation.ValidationException:无法找到默认提供程序

[英]javax.validation.ValidationException: Unable to find default provider

I am currently working on Spring MVC web app and trying to hook up validation using the @Valid annotation. 我目前正在使用Spring MVC Web应用程序并尝试使用@Valid注释挂钩验证。 When I fire up the application I'm getting the following exception: 当我启动应用程序时,我得到以下异常:

javax.validation.ValidationException: Unable to find a default provider

I have Hibernate Validator 3.1.0.GA on the classpath as well as javax validation 1.0.0.GA, Hibernate Core 3.3.1.GA and Hibernate Annotations 3.4.0.GA. 我在类路径上有Hibernate Validator 3.1.0.GA以及javax验证1.0.0.GA,Hibernate Core 3.3.1.GA和Hibernate Annotations 3.4.0.GA.

Is there an incompatiblity in those versions that I'm not seeing, or can anyone think of any reason why I'm still getting this exception with Hibernate Validator on the class path? 在那些我没有看到的版本中是否存在不兼容性,或者是否有人会想到为什么我仍然在类路径上使用Hibernate Validator获得此异常的原因?

Cheers, 干杯,

Caps 帽子

See this answer : https://stackoverflow.com/a/3989936/325742 请参阅此答案: https//stackoverflow.com/a/3989936/325742

To fix, Add this maven dependency Hibernate Validator Annotation Processor . 要修复,添加此maven依赖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 aa NoClassDefFoundError stating that the class org.postgresql.Driver was not found. 假设你有一个NoClassDefFoundError声明没有找到类org.postgresql.Driver

  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 使用Jarvana搜索可以提供org.postgresql.Driver的依赖项,如下所示: http//www.jarvana.com/jarvana/search? search_type = class&java_class = org.postgresql.Driver 在此输入图像描述

  2. Translate the above dependency into maven dependency format : 将上述依赖项转换为maven依赖项格式:

     <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 : 确认上述可在Maven的中央通过搜索像这样
    g:"postgresql" AND a:"postgresql"
    (where g stands for GroupID and a stands for artifactID) (其中, g表示的GroupID和a代表的artifactId)

  4. Finally, add it to your pom.xml 最后,将它添加到您的pom.xml中


Finding Dependencies using m2e 使用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 如果您对所需的依赖关系有一个大致的了解,或者可以找出给定列表所需的依赖关系,那么m2e的依赖关系搜索可以是向pom.xml添加依赖关系的最快方法

Steps : 脚步 :

  1. Click on the Dependencies tab (A) in your pom.xml 单击pom.xml中的Dependencies选项卡(A)
  2. Click on Add (B) 点击添加(B)
  3. Search for the dependency by groupId/artifactId (C) 通过groupId / artifactId(C)搜索依赖项
  4. Double click the required one from the search results to have it added directly to your pom.xml (D) 双击搜索结果中所需的一个,将其直接添加到您的pom.xml(D)

AD marked in the following snapshot : AD标记在以下快照中: 在此输入图像描述


Finding dependencies in IntelliJ Idea 在IntelliJ Idea中查找依赖项

In IntelliJ, looking up a dependency is much easier. 在IntelliJ中,查找依赖项要容易得多。 All you need to do, is to make sure that the maven central repo has been indexed by IntelliJ like so: 您需要做的就是确保maven中央仓库已被IntelliJ索引,如下所示:

在此输入图像描述

And then, go into the pom, do a dep + Tab (or an Alt + Insert as shown here ), and this is what you get: 然后,进入POM,做了DEP + Tab键 (或Alt键 + 插入如图所示这里 ),这是你会得到什么: 在此输入图像描述

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: 如果您所在的类具有未解析的导入,则快速修复程序为您提供了通过在缺少的类/包上执行Alt + Enter来搜索和添加相应的maven存储库的选项: 在此输入图像描述

Awesome I say ! 真棒,我说!


Hibernate Validator 3.1 is not a JSR303 provider. Hibernate Validator 3.1不是JSR303提供程序。 You need to upgrade to Hibernate Validator 4 or later. 您需要升级到Hibernate Validator 4或更高版本。

This happened to me without Hibernate. 没有Hibernate,这发生在我身上。

Running great on my PC, it didn't work on my EC2 Linux server. 在我的电脑上运行良好,它在我的EC2 Linux服务器上无效。

The reason was an existence of validation-api-1.0.0.GA.jar file under /usr/share/tomcat/lib . 原因是/usr/share/tomcat/lib下存在validation-api-1.0.0.GA.jar文件。

Once validation-api-1.0.0.GA.jar deleted, it worked great. validation-api-1.0.0.GA.jar删除后,效果很好。

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. 在我的情况下,我遇到了同样的问题,但它发生了,因为由maven下载的hibernate-core版本4.1.8.Final的jar已损坏。 I swithed to version 4.1.6.Final and it started working. 我转到版本4.1.6.Final,它开始工作。 I was using STS and spring repositories. 我正在使用STS和Spring存储库。

Hope this helps someone. 希望这有助于某人。

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. 在相同的情况下,我只更新我的Jar版本,用于从hibernate-anotation和hibernate-common-annotation到下面列出的Hibernate4 anotations的anotations。 For Hibernate 4 you can use this jars- 对于Hibernate 4,你可以使用这个罐子 -

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

Hope this will work for you also. 希望这对你也有用。

I received the following error: 我收到以下错误:

Invocation of init method failed; 调用init方法失败; nested exception is javax.validation.ValidationException: Unable to get available provider resolvers 嵌套异常是javax.validation.ValidationException:无法获取可用的提供程序解析程序

I discovered that in my WEB-INF/lib directory I had two versions of Validator.class present in both of the following jar files: 我发现在我的WEB-INF / lib目录中,我在以下两个jar文件中都有两个版本的Validator.class:

  • org.springframework.context-3.1.1.RELEASE.jar org.springframework.context-3.1.1.RELEASE.jar
  • com.springsource.javax.validation-1.0.0.GA.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. 我从WEB-INF / lib目录中删除了com.springsource.javax.validation-1.0.0.GA.jar,因为它较旧且不再受支持。 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 我在阅读Spring 3 Validation后想出了哪个文件导致了问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.validation.ValidationException:无法找到默认提供程序 - javax.validation.ValidationException: Unable to find a default provider javax.validation.ValidationException:无法找到默认提供程序-10 - javax.validation.ValidationException: Unable to find a default provider - 10 SpringMvc - javax.validation.ValidationException - SpringMvc - javax.validation.ValidationException javax.validation.ValidationException: HV000063: 无法实例化类 - javax.validation.ValidationException: HV000063: Unable to instantiate class javax.validation.ValidationException: HV000183: 无法加载 'javax.el.ExpressionFactory' - javax.validation.ValidationException: HV000183: Unable to load 'javax.el.ExpressionFactory' ValidationException:无法找到默认提供程序 - ValidationException: Unable to find a default provider 如何解决 javax.validation.ValidationException: HV000064: Unable to instanceiate ConstraintValidator: in Spring - How do get around a javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: in Spring javax.validation.ValidationException:%class%已在xml中配置 - javax.validation.ValidationException: %class% has already be configured in xml javax.validation.ValidationException: HV000041: 调用 TraversableResolver.isReachable() 引发异常 - javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception javax.validation.ValidationException: HV000028: 在测试中 isValid 期间出现意外异常 - javax.validation.ValidationException: HV000028: Unexpected exception during isValid in Test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM