Hibernate:java.lang.NoSuchMethodError:javax / validation / spi / ConfigurationState.getParameterNameProvider()Ljavax / validation / ParameterNameProvider

时间:2013-09-19 17:20:27

标签: hibernate junit4 spring-junit

我们正在为基于Spring-Hibernate的应用程序执行Junit套件(使用spring text conext单元测试框架)。并且使用ANT构建并在Hibernate Jars下面构建路径。

hibernate-validator-5.0.1.Final.jar
validation-api-1.1.0.Final.jar

hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.3.Final.jar
hibernate-ehcache-4.2.3.Final.jar
hibernate-entitymanager-4.2.3.Final.jar

我们得到的错误似乎与Hibernate验证有关。

   java.lang.NoSuchMethodError:javax/validation/spi/ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.(ValidatorFactoryImpl.java:113) at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:45) at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:217) at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:50) at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:445) at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:96) at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150)

2 个答案:

答案 0 :(得分:2)

您很可能在类路径的某个位置(在本例中为1.0.0)中有旧版本的validation-api。与this question非常相似。

答案 1 :(得分:0)

我遇到了这个问题,我认为这是因为我使用的是Spring Boot和一个旧版本的Hibernate?我加上了 compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.3.2.Final'作为依赖项,现在可以使用。

这是我的相关依赖。

// database
compile 'org.hibernate:hibernate-core:4.3.8.Final'
compile group: 'org.hibernate', name: 'hibernate-hikaricp', version: '4.3.8.Final'
compile group: 'hikari-cp', name: 'hikari-cp', version: '1.7.5'

// without this, hibernate util fails in unit test environment -- something with javax.validator / reading
// properties files
compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.3.2.Final'

compile group: 'postgresql', name: 'postgresql', version: '9.3-1102.jdbc41'
compile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.4'


// spring
compile ('org.springframework.boot:spring-boot-starter-web')
// so that we can use a tomcat web container for dev purposes
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.4.3.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.5.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '1.4.3.RELEASE'