java.lang.NoClassDefFoundError:javax / validation / ParameterNameProvider

时间:2023-01-19 21:40:58

I write small hibernate application and get following stacktrace:

我编写小型hibernate应用程序并获取以下stacktrace:

org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:154)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
    at com.beingjavaguys.hbn.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
    at com.beingjavaguys.hbn.HibernateUtil.<clinit>(HibernateUtil.java:10)
    at crud.UserDao.addUser(UserDao.java:12)
    at com.beingjavaguys.hbn.App.main(App.java:53)
Caused by: java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
...

I don't understand the reason of this mistake.

我不明白这个错误的原因。

code:

码:

       Configuration configuration = new Configuration();
        configuration.configure();
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
                configuration.getProperties()).build();
        return configuration.buildSessionFactory(serviceRegistry); // exception thrown here

my pom.xml:

我的pom.xml:

...
<dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.5.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.5.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
         ...
     ...

I have read related topics but I really don't understand how to fix it - I don't want to roll out to hibernate 4.0 version.

我已阅读相关主题但我真的不明白如何解决它 - 我不想推出到hibernate 4.0版本。

How to fix it?

怎么解决?

2 个解决方案

#1


23  

Hibernate Validator 5x is not compatible with validation-api 1.0.x

Hibernate Validator 5x与validation-api 1.0.x不兼容

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

JPA 2.0:在JPA 2.0中使用javax.validation。*包的例外

#2


26  

Just remove the javax.validation dependency

只需删除javax.validation依赖项

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>

That fixed this particular problem on my end.

这解决了我的这个特殊问题。

#1


23  

Hibernate Validator 5x is not compatible with validation-api 1.0.x

Hibernate Validator 5x与validation-api 1.0.x不兼容

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

JPA 2.0:在JPA 2.0中使用javax.validation。*包的例外

#2


26  

Just remove the javax.validation dependency

只需删除javax.validation依赖项

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>

That fixed this particular problem on my end.

这解决了我的这个特殊问题。