javax.validation.ValidationException:无法找到默认提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3982950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.validation.ValidationException: Unable to find default provider
提问by Caps
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 exception:
我目前正在开发 Spring MVC Web 应用程序并尝试使用 @Valid 注释连接验证。当我启动应用程序时,我收到以下异常:
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
帽子
采纳答案by Affe
Hibernate Validator 3.1 is not a JSR303 provider. You need to upgrade to Hibernate Validator 4 or later.
Hibernate Validator 3.1 不是 JSR303 提供者。您需要升级到 Hibernate Validator 4 或更高版本。
回答by Ashutosh Jindal
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 a a NoClassDefFoundError
stating that the class org.postgresql.Driver
was not found.
假设您收到 aaNoClassDefFoundError
说明org.postgresql.Driver
未找到该类。
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.Driverwhich givesTranslate the above dependency into maven dependency format :
<dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency>
Confirm that the above is available at Maven Central by searching like this:
g:"postgresql" AND a:"postgresql"
(whereg
stands for GroupID anda
stands for artifactID)Finally, add it to your pom.xml
使用Jarvana搜索的依赖,可以提供
org.postgresql.Driver
像这样:http://www.jarvana.com/jarvana/search?search_type=class&java_class=org.postgresql.Driver这给将上面的依赖翻译成maven依赖格式:
<dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency>
确认上述可在Maven的中央通过搜索像这样: (其中代表组ID和代表的artifactId)
g:"postgresql" AND a:"postgresql"
g
a
最后,将其添加到您的 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 :
脚步 :
- Click on the Dependencies tab (A) in your pom.xml
- Click on Add (B)
- Search for the dependency by groupId/artifactId (C)
- Double click the required one from the search results to have it added directly to your pom.xml (D)
- 单击 pom.xml 中的 Dependencies 选项卡 (A)
- 单击添加 (B)
- 通过 groupId/artifactId (C) 搜索依赖
- 从搜索结果中双击所需的一个,将其直接添加到您的 pom.xml (D)
A-D marked in the following snapshot :
AD 标记在以下快照中:
Finding dependencies in IntelliJ Idea
在 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:
在 IntelliJ 中,查找依赖项要容易得多。您需要做的就是确保 Maven 中央存储库已被 IntelliJ 索引,如下所示:
And then, go into the pom, do a dep+Tab(or an Alt+Insertas shown here), and this is what you get:
然后,进入POM,做一个dep+ Tab(或Alt+Insert如图所示这里),这是你会得到什么:
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+Enteron the missing Class/Package:
如果您所在的类中存在未解析的导入,那么快速修复为您提供了一个选项,通过在缺少的类/包上执行Alt+来搜索和添加相应的 maven 存储库Enter:
Awesome I say !
我说真棒!
回答by Kof
This happened to me without Hibernate.
这发生在我没有 Hibernate 的情况下。
Running great on my PC, it didn't work on my EC2 Linux server.
在我的 PC 上运行良好,但在我的 EC2 Linux 服务器上却无法运行。
The reason was an existence of validation-api-1.0.0.GA.jar
file under /usr/share/tomcat/lib
.
究其原因,的存在validation-api-1.0.0.GA.jar
下的文件/usr/share/tomcat/lib
。
Once validation-api-1.0.0.GA.jar
deleted, it worked great.
一旦validation-api-1.0.0.GA.jar
被删除,它的工作太棒了。
回答by damian
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.
就我而言,我遇到了同样的问题,但它的发生是因为 maven 下载的 hibernate-core 版本 4.1.8.Final jar 已损坏。我切换到版本 4.1.6.Final 并开始工作。我正在使用 STS 和 spring 存储库。
Hope this helps someone.
希望这可以帮助某人。
回答by pintu
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-
在相同的情况下,我仅将 Jar 版本更新为从 hibernate-antation 和 hibernate-common-annotation 到下面列出的 Hibernate4 注释的注释。对于 Hibernate 4,你可以使用这个 jars-
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.
希望这也适用于您。
回答by Armanda K.
I received the following error:
我收到以下错误:
Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to get available provider resolvers
init 方法调用失败;嵌套异常是 javax.validation.ValidationException: Unable to get available provider resolvers
I discovered that in my WEB-INF/lib directory I had twoversions of Validator.class present in both of the following jar files:
我发现在我的 WEB-INF/lib 目录中,我有两个版本的 Validator.class 存在于以下两个 jar 文件中:
- org.springframework.context-3.1.1.RELEASE.jar
- com.springsource.javax.validation-1.0.0.GA.jar
- 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
我从 WEB-INF/lib 目录中删除了 com.springsource.javax.validation-1.0.0.GA.jar,因为它较旧且不再受支持。这样做之后,我的应用程序运行良好。我从其他帖子中了解到我的问题与类路径上同一文件的重复版本有关。阅读Spring 3 Validation后,我找出了导致问题的文件