我们正在为基于Spring-Hibernate的应用程序执行Junit套件(使用Spring text conext单元测试框架),并使用ANT进行构建,并且在构建路径中存在Hibernatejars。
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
我们得到以下错误似乎与休眠验证有关。
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)
很可能你的类路径上有旧版本的验证 api(在本例中为 1.0.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'