java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48323244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName
提问by asabd
JDK: 1.8.0_131
JDK:1.8.0_131
Tomcat: 8.0.27.0
雄猫:8.0.27.0
Hibernate Validator: 6.0.7.Final + all the dependencies downloaded from: Hibernate Validator 6
Hibernate Validator: 6.0.7.Final + 从以下位置下载的所有依赖项:Hibernate Validator 6
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public AccountSyncResponse excute(AccountSyncRequest account_sync_request_)
{
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<AccountSyncRequest>> violations = validator.validate(account_sync_request_);
.
.
.
.
AccountSyncResponse _AccountSyncResponse = new AccountSyncResponse();
return _AccountSyncResponse;
}
The code fail on Validation.buildDefaultValidatorFactory()
with the exception:
代码失败Validation.buildDefaultValidatorFactory()
,但异常:
java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
at org.hibernate.validator.internal.xml.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:63)
at org.hibernate.validator.internal.engine.ConfigurationImpl.parseValidationXml(ConfigurationImpl.java:527)
at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:328)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
It looks like the wrong jar file is being used but I can't figure out which one.
看起来使用了错误的 jar 文件,但我不知道是哪个。
回答by Chris Ritchie
I had this same issue after upgrading from Springboot 1.5.x to Springboot2. The solution was to upgrade Java EE 7 to Java EE 8:
从 Springboot 1.5.x 升级到 Springboot2 后,我遇到了同样的问题。解决方案是将 Java EE 7 升级到 Java EE 8:
From:
从:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
To:
到:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
回答by banterCZ
Spring Boot 2 comes with hibernate-validator 6(org.hibernate.validator:hibernate-validator:6.0.16.Final
, which depends on validation-api 2(javax.validation:validation-api:2.0.1.Final
), which is specific for Java EE 8, see Appendix F. Dependency versions. But it may happen that you have to support older application servers with Java EE 7 only. Spring Framework 5should still suport it, see runtime support.
Spring Boot 2 附带了hibernate-validator 6( org.hibernate.validator:hibernate-validator:6.0.16.Final
,它依赖于validation-api 2( javax.validation:validation-api:2.0.1.Final
),它是 Java EE 8 特有的,参见附录 F. 依赖版本。但可能会发生你必须用 Java 支持旧的应用服务器仅限 EE 7。Spring Framework 5仍应支持它,请参阅运行时支持。
In that case, use older hibernate-validator(5.4.3.Final) and validation-api(1.1.0.Final). If you use Spring Boot maven parent, just define these properties.
在这种情况下,请使用较旧的hibernate-validator( 5.4.3.Final) 和validation-api( 1.1.0.Final)。如果使用 Spring Boot maven parent,只需定义这些属性即可。
<properties>
<javax-validation.version>1.1.0.Final</javax-validation.version>
<hibernate-validator.version>5.4.3.Final</hibernate-validator.version>
</properties>
The problem is that hibernate-validatorhas changed the groupId
since version 6, so you have to exclude the new group but add the old one, e.g.
问题是hibernate-validator已更改groupId
自版本 6 以来的内容,因此您必须排除新组但添加旧组,例如
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>