当前位置: 首页 > 工具软件 > Validation > 使用案例 >

javax.validation.ParameterNameProvider

慎志国
2023-12-01

今天在做spring和hibernate整合的时候遇到这个问题:

Caused by: java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
	at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)
	at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
	at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
	at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:445)
	at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:96)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150)
	... 50 more

解决方法:

As @Korgen mentioned in comments hibernate-validator-5.x.x doesn't compatible with validation-api-1.0.x. This is because of moving to new specification JSR-303 -> JSR-349.

1.  由于hibernate-validator-5.x.x已经不兼容validation-api-1.0.x,这是因为在hibernate-validator-5.x.xhibernate-validator-5.x.x已经把旧的校验框架JSR-303,改变为JSR-349了。

2.  这里有两套解决方案:

                                         1>  把hibernate-validator换成4版本的

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.3.1.Final</version>
</dependency>

                                        2>  把javax.validation更新到较高版本

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>

参考: http://stackoverflow.com/questions/14730329/jpa-2-0-exception-to-use-javax-validation-package-in-jpa-2-0

 类似资料:

相关阅读

相关文章

相关问答