Spring Boot Actuator Refresh无法更新应用专属配置文件问题排查
问题:Spring Cloud Config应用专属配置文件刷新失效
环境:Spring Boot 2.7.1、Spring Cloud 2021.0.3
现象:
- 更新应用专属配置文件(如
ApplicationName.properties)或应用子目录下的application.properties后,调用/actuator/refresh仅返回["config.client.version"],服务属性未实际更新 - 但更新Config Server根目录的
application.properties时,/actuator/refresh可正常刷新属性
已配置项: - 配置类标注
@RefreshScope - 已正确暴露并启用refresh端点
- bootstrap文件指定了Config Server地址及应用名称配置
解决方案
1. 显式配置刷新范围,纳入应用专属配置源
在application.yml中添加以下配置,让刷新机制包含Config Client拉取的应用专属配置源:
spring: cloud: refresh: extra-refreshable: - org.springframework.cloud.config.client.ConfigServicePropertySource
2. 确保属性绑定方式正确
如果使用@Value注入属性,需确保所在类标注@RefreshScope;更推荐结合@ConfigurationProperties使用,可靠性更高:
@RefreshScope @ConfigurationProperties(prefix = "your.app.prefix") public class AppConfig { private String targetProperty; // 生成getter、setter方法 }
3. 验证基础刷新开关
确认未禁用Config Client的刷新功能(默认启用,若被修改需修正):
spring: cloud: config: refresh: enabled: true
原因说明
Spring Cloud 2021.0.x(对应Spring Boot 2.6+)调整了默认刷新范围,仅将根目录application.properties这类全局配置纳入默认刷新列表,应用专属的配置源需通过spring.cloud.refresh.extra-refreshable显式声明才能被/actuator/refresh识别。而Spring Cloud 2020.0.x(对应Spring Boot 2.3.x)默认包含了应用专属配置源,因此之前版本无需额外配置。
内容的提问来源于stack exchange,提问作者Dan
相关产品推荐
相关产品推荐

