【问题标题】:Spring Cloud Config fails to update properties dynamicallySpring Cloud Config 无法动态更新属性
【发布时间】:2019-12-25 23:25:29
【问题描述】:

我有一个 Camel Spring Boot 应用程序,我在其中打印使用 Spring Cloud Config Server 设置的属性的值(通过 Git commit id 插件)。问题在于,一旦将值提交给 Git,Camel 应用程序中的属性值就不会更新。我必须重新启动无法达到 Spring Cloud Config 服务器目的的 Camel 应用程序。请注意,我们在本地机器上使用 Git 文件系统。

属性文件的名称是 CamelSpringBootSample-dev.properties。

只要我提交,配置服务器就会在刷新时在端点发布更新的值: http://localhost:8888/CamelSpringBootSample/dev

我还在以下位置提供了 Camel 应用程序端点: http://localhost:8181/actuator/env

这里的属性值不会在刷新时更新。但是,如果我重新启动 Camel 应用程序,则该值正在反映。

三个项目的源代码都上传到github.com。

  1. 配置服务器:https://github.com/sreejeshraj/config-server

  2. Camel 客户端项目(使用配置服务器自行配置):https://github.com/sreejeshraj/camel-config-server 请不要被存储库名称 camel-config-server 误导。这是配置服务器的客户端,不小心命名错误,见谅。

  3. 存储配置属性的本地git仓库:https://github.com/sreejeshraj/Git-Config

请注意,我在 Spring bean 组件类中使用了注解 @RefreshScope。

你能帮我解决这个问题吗?提前致谢。

【问题讨论】:

标签: spring-boot apache-camel spring-cloud-config


【解决方案1】:

你必须设置:

management.endpoints.web.exposure.include=refresh

bootstrap.propertiesbootstrap.yml

并触发/actuator/refresh 端点。

@RefreshScope and /refresh not working

请注意,正如 cmets 中所说,Camel 在 Spring bean 刷新时不会更新其值,并且没有计划实现此功能。 (https://issues.apache.org/jira/browse/CAMEL-13892)。您可能可以通过Spring Cloud Bus 找到解决方案。

【讨论】:

  • 感谢 Ortomala Lokni 指出这一点。我已经发布了 /actuator/refresh 端点。发生的事情有点奇怪:1.当我调用localhost:8181/actuator/env端点(属于Camel应用程序)时,属性的更新值按预期反映。 2. 但是 Camel 在打印时仍然使用旧值。基本上,应用程序没有使用更新后的值。你能帮忙吗?
  • 在重新启动 Camel 应用程序时,它会反映更新后的值。但是,这没有达到 Spring Cloud 配置的目的。
  • 尝试直接从带有@RefreshScope注解的bean打印出刷新的值。问题可能是 Camel 没有重新读取该值。
  • 是的,刷新是Spring Actuator的一个特性,它只是刷新注解的Spring Beans,不知道Camel。因此,这取决于您如何在 Camel 中使用更新的属性。必须在消息处理时重新计算,否则无法使用更新后的值。
  • Camel 不支持 Spring Cloud 配置功能 - 得到官方确认。请看issues.apache.org/jira/browse/CAMEL-13892
【解决方案2】:

正如@ortomala-lokni 已经指出的那样,您需要在更新发生后刷新您的配置使用者

如果您想要一个集中式解决方案来完成这项任务(自动刷新许多组件),请查看Spring Cloud Bus

This page 对该主题进行了很好的概述。

【讨论】:

  • 谢谢Burki,我正准备稍后尝试Spring Cloud Bus。关于刷新端点,请看我的cmets下面Ortomala的回复。
【解决方案3】:

我的客户端中有application.propertiesbootstrap.properties 文件。在这种情况下,您应该在 bootstrap.yml 中指定 spring.application.namespring.cloud.config.server.git.uri。我没有刷新在applicaiton.properties 中包含spring.application.name 的属性。

【讨论】:

    猜你喜欢
    • 2021-05-07
    • 2015-05-14
    • 2021-04-13
    • 2016-02-23
    • 2019-03-26
    • 2021-03-15
    • 1970-01-01
    • 2022-01-09
    • 2018-09-23
    相关资源
    最近更新 更多