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

Spring Boot升级至3.4.0后GCP SecretManager配置方式失效

Spring Boot 3.4.0升级后GCP SecretManager配置引用失效导致数据源连接失败

背景

我们将Spring Boot版本从3.3.6升级至3.4.0,同步更新了相关依赖版本:

  • org.springframework.boot: 3.3.6 → 3.4.0
  • com.google.cloud:spring-cloud-gcp-dependencies: 5.8.0 → 5.9.0
  • org.springframework.cloud:spring-cloud-dependencies: 2023.0.4 → 2024.0.0
  • org.springdoc:springdoc-openapi-starter-webmvc-ui: 2.6.0 → 2.7.0

问题

升级完成后,因使用GCP SecretManager存储数据库连接信息,导致数据源连接失败。

问题详情与测试

在application.yml中配置了SecretManager导入及数据库信息:

# application.yml
spring:
  config:
    import: "sm://"
  datasource:
    url: jdbc:postgresql://localhost:5432/cehr?currentSchema=XXXX
    username: ${sm://psql-username}
    password: ${sm://psql-password}

编写测试代码验证配置解析情况:

@Service
public class XXXService extends CommonService {

    @Autowired
    private SecretManagerTemplate secretManagerTemplate;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    @Value("${sm://psql-username}")
    private String username2;

    @Value("${sm://psql-password}")
    private String password2;

    public void execute() {
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        System.out.println("username2 = " + username2);
        System.out.println("password2 = " + password2);
        System.out.println("psql-username = " + secretManagerTemplate.getSecretString("sm://psql-username"));
        System.out.println("psql-password = " + secretManagerTemplate.getSecretString("sm://psql-password"));
    }
}

执行后输出结果:

username = //psql-username
password = //psql-password
username2 = //psql-username
password2 = //psql-password
psql-username = ********** (正确值)
psql-password = ********** (正确值)

问题分析

  • 通过SecretManagerTemplate直接调用SecretManager可以正常获取到正确的凭证值
  • 通过application.yml中${sm://xxx}格式引用SecretManager的方式失效,配置未被正确解析,仅保留了//xxx部分

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 11:36:08