You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3配置Spring Cloud Vault启动遇NoClassDefFoundError错误

Spring Boot 3集成Vault启动报错:NoClassDefFoundError 解决方案

问题现象

在Spring Boot 3项目中配置spring.config.import: vault://后,应用启动失败,抛出如下错误:

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

环境信息

  • Spring Boot 3.0.0
  • JDK 19.0.1
  • 项目使用spring-cloud-starter-vault-config 3.1.1版本
  • 配置文件application.yml启用了Vault的APPROLE认证方式

问题原因

Spring Boot 3对应的Spring Cloud 2022.0.x版本(代号Kilburn),其Spring Cloud Vault组件依赖Apache HttpClient 5.x,但当前项目依赖中缺少HttpClient 5的核心jar包,导致类加载失败。

解决办法

在pom.xml中添加Apache HttpClient 5的依赖:

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

或者通过Spring Boot官方starter间接引入:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-httpclient</artifactId>
</dependency>

添加依赖后重新构建项目,启动即可恢复正常。

补充说明

  • 注释spring.config.import: vault://后应用能正常启动,是因为此时不会触发Vault配置加载流程,无需调用HttpClient相关类
  • Spring Boot 2.x版本可正常运行,是因为对应Spring Cloud版本依赖的是Apache HttpClient 4.x,该依赖已被包含在相关starter中

内容的提问来源于stack exchange,提问作者Alexander Tilkin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 04:00:29