spring-boot - 为什么 Spring Boot 应用程序不断从配置服务中获取配置?
问题描述
我正在使用 Spring Boot 和 Spring Cloud Config 构建微服务。从日志文件中,我可以看到我的一个应用程序每五分钟向配置服务发送一个请求以进行配置,而其他应用程序则不执行相同的行为。
06:04:28.586 [serviceId:xxx-service/traceId:545d584f10da3123/spanId:545d584f10da3123/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:04:30.135 [serviceId:xxx-service/traceId:545d584f10da3123/spanId:545d584f10da3123/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:09:30.367 [serviceId:xxx-service/traceId:519fdde3a2d8ce5a/spanId:519fdde3a2d8ce5a/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:09:31.928 [serviceId:xxx-service/traceId:519fdde3a2d8ce5a/spanId:519fdde3a2d8ce5a/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:14:32.035 [serviceId:xxx-service/traceId:e32c45c3a5c3fcca/spanId:e32c45c3a5c3fcca/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:14:33.611 [serviceId:xxx-service/traceId:e32c45c3a5c3fcca/spanId:e32c45c3a5c3fcca/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:19:32.033 [serviceId:xxx-service/traceId:16fc982b0638d4a6/spanId:16fc982b0638d4a6/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:19:33.495 [serviceId:xxx-service/traceId:16fc982b0638d4a6/spanId:16fc982b0638d4a6/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:24:32.036 [serviceId:xxx-service/traceId:f4eae364e2624d58/spanId:f4eae364e2624d58/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:24:33.640 [serviceId:xxx-service/traceId:f4eae364e2624d58/spanId:f4eae364e2624d58/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
我试图理解这种行为。
1bootstrap.yml
该服务是否有别于其他服务,导致独特的行为?
不,所有服务bootstrap.yml
似乎都是相同的结构,没有不同的配置键:
spring:
profiles:
active: dev
cloud:
config:
name: xxxservice
label: master
uri: http://config-service
2 该服务是否试图动态且定期地刷新其配置?
不,为了动态刷新一个spring boot应用的配置,我们需要:
- 将
@RefreshScope
注解放在课堂阅读配置上 - 调用类似
curl -X POST http://xx:8080/refresh
手动触发刷新的方法
所以不应该有周期性的自动刷新行为。
问题仍未解决,希望有人直接解释这种情况或指出我的陈述中的任何错误。
解决方案
我不知道为什么您在其他服务中没有看到这种情况,但我相信这种行为是由于客户端想要定期检查服务器的运行状况。来自 Spring Cloud Config Client 文档:
7.8.1 健康指标
Config Client 提供了一个 Spring Boot Health Indicator,它尝试从 Config Server 加载配置。可以通过设置禁用运行状况指示器
health.config.enabled=false
。出于性能原因,响应也会被缓存。默认缓存时间为 5 分钟。要更改该值,请设置 health.config.time-to-live 属性(以毫秒为单位)。
所以只需 set health.config.enabled=false
,这种行为应该停止。
推荐阅读
- html - 如何在纯 html 中禁用 ctrl+u amd F12
- r - 在运行 if else 循环时管理数据帧中的 NA 值
- javascript - CoffeeScript 错误与实际代码不同
- json - 如何在折线传单周围添加多边形
- html - 为什么可以在snippets.json中自定义css缩写而不是html:5?
- asp.net-mvc - AngularJS 5 在项目中的使用
- arrays - 在数组中查找重复连续值的最短方法
- java - Spring Boot Devtools如何在独立模块中重新加载Maven多个依赖模块?
- r - 提取 R 中 DT 每一行的第 n 列,其中 n 是 DT 中行数的向量
- autohotkey - 重新映射 ctrl+win