java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName
Asked Answered
D

3

27

JDK: 1.8.0_131

Tomcat: 8.0.27.0

Hibernate Validator: 6.0.7.Final + all the dependencies downloaded from: 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:

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.

Diesis answered 18/1, 2018 at 14:9 Comment(3)
Check if this answer helps you: #47947793Aspirin
Hi @asabd, how did you fix this issue? I have a similar error: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;Bombe
I got the same exception: java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String; at org.hibernate.validator.internal.xml.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:61) with tags are [maven] [java ee].Exculpate
I
19

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:

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>
Iggie answered 10/9, 2018 at 22:27 Comment(2)
The version 8 should not be needed. See The Java EE 7 API level is required in Spring's corresponding modules now, with runtime support for the EE 8 level github.com/spring-projects/spring-framework/wiki/…Karaite
In upgrading an application, I have come across a closely related issue, I was getting the Exception in the title. The change in the pom I needed was javax:javaee-web-api:jar:7.0:provided to javax:javaee-web-api:jar:8.0:provided (I'm on Java 11). I now get a different Exception, but know how to deal with that! ... I think!Shoot
K
16

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 5 should still suport it, see runtime support.

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.

<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-validator has changed the groupId since version 6, so you have to exclude the new group but add the old one, e.g.

<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>
Karaite answered 28/1, 2020 at 14:0 Comment(0)
E
9

I've just added validation-api dependency to my pom.xml and it works!

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
</dependency>
Erdrich answered 7/5, 2021 at 10:37 Comment(1)
This worked for me. Some transitive dependency polluted my classpath with a 1.x version of the validation-api. Explicit declaration of 2.0.2 solved the dependency eviction race in sbt.Bates

© 2022 - 2024 — McMap. All rights reserved.