SpringBoot 3 with Spring Cloud Vault 3.1.1 Runtime Error java.lang.NoClassDefFoundError: org/apache/hc/client5/http/classic/HttpClient

9.1k views Asked by At

Application in Spring-boot 3 fails to start when spring.config.import: vault:// set. With the following error:

16:54:21.649 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoClassDefFoundError: org/apache/hc/client5/http/classic/HttpClient

Description:

  • Spring Boot 3
  • JDK 19

Environment state:

JAVA_HOME: /Users/USER/Library/jdk-19.0.1.jdk/Contents/Home

Java Version:

❯ java --version
openjdk 19.0.1 2022-10-
OpenJDK Runtime Environment (build 19.0.1+10
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

application.yml:

spring:
  config:
    import: vault://

spring.cloud.vault:
  enabled: true
  application-name: APP
  host: ${VAULT_HOST}
  port: 8200
  scheme: https
  namespace: admin
  fail-fast: true
  config:
    lifecycle:
      enabled: true
      min-renewal: 10s
      expiry-threshold: 1m
  authentication: APPROLE
  app-role:
    role-id: ${VAULT_ROLE_ID}
    secret-id: ${VAULT_SECRET_ID}
    role: ${VAULT_ROLE}
    app-role-path: approle

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example.newSpring</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>19</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-vault-config</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Notes

  • When I run the application with Spring Boot 3 and comment spring.config.import: vault:// the application starts
  • When I run the application with Spring Boot 2.x.y the application starts
2

There are 2 answers

1
Brian Clozel On

Your application is mixing incompatible versions, as support for the Apache HttpComponents client 4.x has been removed in Spring Framework (and Spring projects in general).

Please use spring-cloud-starter-vault-config with version 4.0.0+.

0
megloff On

For Spring Boot 3 I had to add the following maven dependencies. Afterwards my old migrated code was working.

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
</dependency>