0

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
Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
Alexander Tilkin
  • 149
  • 1
  • 2
  • 13
  • Probably `org.apache.httpcomponents.client5:httpclien` was removed as dependency of a package so now maven cant load as transitive dependency. Try to add this to maven dependencies and check: https://search.maven.org/artifact/org.apache.httpcomponents.client5/httpclient5/5.2/jar – zlaval Nov 29 '22 at 18:38
  • I added the dependency and run the application. This is the error I received. java.lang.NoSuchMethodError: 'void org.springframework.http.client.HttpComponentsClientHttpRequestFactory.(org.apache.http.client.HttpClient)' – Alexander Tilkin Nov 30 '22 at 03:55

2 Answers2

6

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>
megloff
  • 1,400
  • 4
  • 27
  • 44
1

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+.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • Spring Cloud Vault 4.0.0 was released on Dec 16, 2022. Several weeks after the release of Spring Boot 3 and my upgrade trial, I couldn't use 4.0.0 at the time. Thank you for your update anyway – Alexander Tilkin Dec 25 '22 at 08:16