简体   繁体   中英

Hibernate Validator java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

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:

[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]

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

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.

I have loads of other dependencies in this project(eg 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?)

Is there any help?

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

  1. classmate-0.8.0.jar 2.jboss-logging-3.1.0.ga.jar

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.

Once I added it to the classpath, the class def not found error went away.

I would suspect multiple implementations of javax.el. That's usually what causes this sort of issues.

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.

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 ..

First, check all dependencies using mvn dependency:tree - Find hibernate-validator and add below one into pom.xml inside respective dependency - if not required.

<exclusion>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
</exclusion>

Add this in spring-servelt.xml

 <beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> </beans:bean> 

and following jars

  1. hibernate-validator-6.0.17.Final.jar
  2. validation-api-2.0.1.Final.jar
  3. classmate-1.3.4.jar
  4. jboss-logging-3.3.2.Final.jar

then all will work fine.

Happy to help...

I had this issue when working on a spring-boot application. The problem was caused by hibernate-validator 6.0.11 which seems to have an erroneous dependency on javax validation-api 2.0.1.Final . For me the solution was to upgrade to a higher version of hibernate-validator.

In more detail:
My application was depending on spring-boot-starter-parent 2.1.18.RELEASE . The spring-boot-starter-web package depends on hibernate-validator 6.0.11 , which itself depends on validation-api-2.0.1.Final . validation-api-2.0.1.Final however requires a higher version of the hibernate validator causing the ValueExtractorManager NoClassDefFoundError. The problem was fixed after upgrading the application to spring-boot-starter-parent 2.1.18.RELEASE which utilizes hibernate-validator 6.0.21.Final .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM