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

Spring Boot 1.5.0升级2.0.0后无法读取Vault配置求助

问题解决:Spring Boot 2.0升级后Vault配置读取失败

1. 修正配置前缀与缩进

Spring Cloud Vault在Finchley版本(对应Spring Boot 2.0)中,配置前缀从spring.vault改为spring.cloud.vault,同时你的bootstrap.yml存在缩进错误,正确配置如下:

spring:
  cloud:
    vault:
      enabled: true
      authentication: TOKEN
      host: ${VAULT_ADDR:localhost}
      port: ${VAULT_PORT:8200}
      token: ${VAULT_TOKEN:eafaa220-901acaafffb5}
      scheme: http

2. 添加Validation依赖

报错提示No validator could be found for constraint 'javax.validation.constraints.NotEmpty',说明缺少JSR-380验证依赖。Spring Boot 2.0中spring-boot-starter-validation需单独引入,修改build.gradle:

springBootVersion = '2.0.9.RELEASE'
springCloudVersion = 'Finchley.SR4'

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-configuration-processor')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.cloud:spring-cloud-starter-consul-config')
compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
implementation('org.springframework.cloud:spring-cloud-starter-vault-config')
// 新增Validation依赖
compile('org.springframework.boot:spring-boot-starter-validation')

3. 验证配置加载逻辑

  • 确认spring-cloud-starter-vault-config依赖已正确引入(当前配置已包含)
  • 本地启动时,检查VAULT_ADDR、VAULT_PORT、VAULT_TOKEN环境变量是否正确,或确认配置中的默认值生效

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 22:08:17