java.lang.NoSuchMethodError:javax.validation.BootstrapConfiguration.getClockProviderClassName

问题描述 投票:8回答:1

JDK:1.8.0_131

Tomcat:8.0.27.0

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;    
    }

代码在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)

看起来好像正在使用错误的jar文件,但我无法弄清楚哪一个。

java hibernate validation bean-validation hibernate-validator
1个回答
4
投票

从Spring Boot 1.5.x升级到Spring Boot 2后,我遇到了同样的问题。解决方案是将Java EE 7升级到Java EE 8:

从:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>

至:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0</version>
    <scope>provided</scope>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.