休眠验证器 java.lang.NoClassDefFoundError:无法初始化类 org.hibernate.validator.internal.engine.ConfigurationImpl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47163434/
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
Hibernate Validator java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl
提问by kerox___m
I have read this and this, but that didn't help...
I am using hibernate validator with the following versions/dependencies:
我正在使用具有以下版本/依赖项的休眠验证器:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.FINAL</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
I thought I'm doing everything correctly, and my logs (with verbose:class as a flag) tell me that:
我以为我做的一切都是正确的,我的日志(以 verbose:class 作为标志)告诉我:
[Loaded org.hibernate.validator.internal.engine.ConfigurationImpl from file:.../hibernate-validator-5.4.1.Final.jar]
[Loaded javax.validation.Validation from file:.../validation-api-1.1.0.Final.jar]
[从文件加载 org.hibernate.validator.internal.engine.ConfigurationImpl:.../hibernate-validator-5.4.1.Final.jar]
[从文件加载 javax.validation.Validation:.../validation-api-1.1.0.Final.jar]
But later at runtime, when I use
但稍后在运行时,当我使用
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
I get the classic error:
我得到经典错误:
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl
java.lang.NoClassDefFoundError: 无法初始化类 org.hibernate.validator.internal.engine.ConfigurationImpl
I also tried downgrading to hibernate-validator 4.3.1 and javax.validation-api 1.0.0, but the error weirdly enough remained the same.
我还尝试降级到 hibernate-validator 4.3.1 和 javax.validation-api 1.0.0,但奇怪的是错误仍然相同。
I have loads of other dependencies in this project(e.g. Spring etc.) , but as far as I can see, none that use hibernate-validator or the javax validation api. (If that were the case, I'd also see them loaded in the logs, wouldn't I?)
我在这个项目中有很多其他依赖项(例如 Spring 等),但据我所知,没有一个使用 hibernate-validator 或 javax 验证 api。(如果是这样,我也会看到它们加载到日志中,不是吗?)
Is there any help?
有什么帮助吗?
回答by Rakesh Bhagat
I was facing the same issue while working with JSR 303 bean validation I have added below two jar(along with validation-api-1.1.0.final.jar and hibernate-validator-5.0.1.final.jar) and the issue got resolved
我在使用 JSR 303 bean 验证时遇到了同样的问题,我在两个 jar 下添加了(以及validation-api-1.1.0.final.jar 和 hibernate-validator-5.0.1.final.jar),问题得到了解决
- classmate-0.8.0.jar 2.jboss-logging-3.1.0.ga.jar
- classmate-0.8.0.jar 2.jboss-logging-3.1.0.ga.jar
回答by 99Sono
For me the problem was that Hibernate Validator depended on jboss-logging. And the jboss logging was not part of my classpath. The exception was not telling me that the class not def found error while trying to instantiate the hibernate configuration impl was from missing jboss logging on the classpath.
对我来说,问题是 Hibernate Validator 依赖于 jboss-logging。并且 jboss 日志记录不是我的类路径的一部分。异常并没有告诉我在尝试实例化休眠配置实现时,类未定义错误是由于缺少 jboss 日志记录在类路径上。
Once I added it to the classpath, the class def not found error went away.
一旦我将它添加到类路径中,类 def not found 错误就消失了。
回答by Atul Jain
First, check all dependencies using mvn dependency:tree
- Find hibernate-validator
and add below one into pom.xml inside respective dependency - if not required.
首先,使用mvn dependency:tree
- 查找所有依赖项hibernate-validator
并将其添加到相应依赖项内的 pom.xml 中 - 如果不需要。
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
回答by Pramod Wayabase
Add this in spring-servelt.xml
在 spring-servelt.xml 中添加这个
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> </beans:bean>
and following jars
和以下罐子
- hibernate-validator-6.0.17.Final.jar
- validation-api-2.0.1.Final.jar
- classmate-1.3.4.jar
- jboss-logging-3.3.2.Final.jar
- hibernate-validator-6.0.17.Final.jar
- 验证-api-2.0.1.Final.jar
- 同学-1.3.4.jar
- jboss-logging-3.3.2.Final.jar
then all will work fine.
那么一切都会正常的。
Happy to help...
乐于帮助...
回答by Guillaume Smet
I would suspect multiple implementations of javax.el. That's usually what causes this sort of issues.
我怀疑 javax.el 的多个实现。这通常是导致此类问题的原因。
Check that you don't have another one with a different name.
检查您是否没有其他名称不同的名称。
If it's not that, add a checkpoint in the ConfigurationImpl constructor and check what's failing.
如果不是这样,请在 ConfigurationImpl 构造函数中添加一个检查点并检查发生了什么故障。
回答by FuSsA
Try like this config :
试试这个配置:
<properties>
<hibernate.version>4.3.11.Final</hibernate.version>
</properties>
<dependencies>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- jsr303 validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
</dependencies>
For a complete example..
对于一个完整的例子..