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

SpringBoot 2.1.4升级至2.5.0后AWS ECS部署读取Secrets Manager异常

问题根因

Spring Boot 2.4 版本开始默认弃用了原有的bootstrap上下文加载逻辑,而AWS Secrets Manager的配置属性注入依赖Spring Cloud的bootstrap上下文初始化流程,也就是你观察到的PropertySourceBootstrapConfiguration Bean没有被加载的核心原因。
你之前添加的spring.config.use-legacy-processing配置没有生效,是因为你把该配置放在了aws profile的激活条件块内,而bootstrap上下文的加载时机早于profile激活阶段,此时aws profile还未生效,配置无法被读取。

解决方案

方案一(推荐,适配新版Spring Cloud规范)

无需开启兼容模式,直接引入bootstrap上下文支持依赖即可:

  1. 在build.gradle的依赖中添加:
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
  1. 修复依赖版本不兼容问题:
    你当前使用的Spring Boot 2.5.0对应Spring Cloud 2020.0.x版本系列,而你引入的spring-cloud-starter-aws-secrets-manager-config:2.2.6.RELEASE属于Hoxton版本系列,和Spring Boot 2.5.x不兼容,会导致自动配置失效。建议通过BOM统一管理版本:
  • 打开你注释的dependencyManagement配置,修改为:
dependencyManagement {
  imports {
    mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.5'
    mavenBom 'io.awspring.cloud:spring-cloud-aws-dependencies:2.3.5'
  }
}
  • 调整原有AWS Secrets Manager相关依赖声明,移除硬编码的版本号:
implementation 'org.springframework.cloud:spring-cloud-context'
implementation 'io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config'
compile group: 'com.amazonaws', name: 'aws-java-sdk-secretsmanager'

方案二(兼容旧版逻辑)

如果你需要沿用旧版的配置加载逻辑:

  1. 新增bootstrap.yml文件放在resources根目录,添加以下配置:
spring:
  cloud:
    aws:
      secretsmanager:
        enabled: true
  config:
    use-legacy-processing: true
  1. 删除application.yml中放在aws profile块内的use-legacy-processing配置。
  2. 同样按方案一的要求修复依赖版本兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 04:12:00