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

使用Actuator/Refresh刷新Git配置服务器,无法更新配置值求助

问题分析与解决方案

1. 修复依赖拼写错误

你的依赖配置里存在明显拼写错误,spring-boot-starter-actuator后缀多了一个x,这会导致依赖无法正常引入,直接影响Actuator的Refresh功能:

// 错误写法
implementation 'org.springframework.boot:spring-boot-starter-actuator'x
// 修正后
implementation 'org.springframework.boot:spring-boot-starter-actuator'

2. 修正Git配置文件语法

你的transfer-prod.properties中maintenance=false new不符合properties文件规范,键值对应为key=value格式,空格会被解析为值的一部分,导致配置无法被正确识别。修改为标准格式:

message=transfer.prod 
maintenance=false

修改后需确保Git提交成功,保证配置服务器能拉取到最新内容。

3. 调整BOM依赖的引入方式

spring-cloud-bus-dependencies是物料清单(BOM),不能直接用implementation引入,正确方式是在依赖管理中导入:

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-bus-dependencies:4.1.0'
    }
}

如果不需要Spring Cloud Bus功能,直接移除该依赖即可,单独使用Actuator Refresh不需要Bus依赖。

4. 替换过时配置项

endpoints.actuator.enabled=true是Spring Boot旧版本配置,新版本应使用:

management.endpoint.actuator.enabled=true

不过你已配置management.endpoints.web.exposure.include=*,该配置已包含暴露Actuator端点的功能,可直接保留。

5. 验证配置服务器的配置更新状态

调用客户端Refresh接口前,先访问配置服务器端点http://localhost:8888/transfer/prod,确认返回的JSON中包含最新的maintenance值。如果配置服务器未更新,说明Git修改未被拉取,可重启配置服务器,或通过spring.cloud.config.server.git.refresh-rate配置Git刷新间隔。

6. 确认客户端配置加载逻辑

由于你引入了spring-cloud-starter-bootstrap,Spring Cloud 2022+版本默认禁用bootstrap机制,该依赖会重新启用它。当前spring.config.import=optional:configserver:http://localhost:8888配置正确,可额外添加spring.cloud.config.profile=prod明确指定拉取的环境配置。

7. 测试刷新流程

完成以上修正后,按以下步骤验证:

  1. 修改Git上transfer-prod.properties的maintenance值并提交。
  2. 确认配置服务器返回最新配置。
  3. 调用客户端POST http://localhost:8081/actuator/refresh接口。
  4. 调用GET http://localhost:8081/value查看返回值是否更新,同时检查Refresh接口返回是否包含maintenance。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 17:03:24