【问题标题】:Spring Cloud Config Server Not picking changesSpring Cloud Config Server 不选择更改
【发布时间】:2020-11-01 19:29:46
【问题描述】:

我正在尝试使用本地文件系统设置 spring 配置云。

以下是我在云服务器上的配置。

server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/

客户端应用上的Bootstrap.properties如下所示

spring.application.name=hello-world
spring.cloud.config.uri=http://localhost:8888
management.endpoints.web.exposure.include=*

我还在类路径上为 hello-world spring boot 应用程序创建了 hello-world.yml,属性为 test: Hello World

按照以下步骤使用配置服务器。

  • 第一步:更新配置文件并启动云配置服务器。能够 见配置http://localhost:8888/hello-world/default

  • 第 2 步:启动客户端应用程序hello-world,客户端应用程序能够读取 test 来自云配置服务器的属性文件。

  • 第 3 步:通过更新 test: Good Bye 来更改配置 hello-world.yaml。

    此时,如果我检查 http://localhost:8888/hello-world/default ,它仍然显示旧值。

  • 第 4 步:在客户端应用程序上运行 /actuator/refresh。但它不会检测到 配置服务器上的任何更改。

仅当我重新启动云配置服务器时才会反映新的更改。 是否有任何配置问题导致云配置服务器无法监听更改?

我可以在云配置应用程序上看到o.s.cloud.commons.util.InetUtils : Cannot determine local hostname INFO 登录。

【问题讨论】:

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


    【解决方案1】:

    首先,我按照您所遵循的完全相同的步骤得到了同样的问题,经过几乎一天的搜索和研究,发现了以下问题,

    1. 我们不应该使用classpath:/<whatever> spring.cloud.config.server.native.searchLocations 因为当我们使用 so 构建项目并运行时,位置是指生成的 .jar 文件中的目录,所以我们将无法在运行时更新它。

    要确认这一点,您可以停止配置服务器,打开 .jar 存档并删除 hello-world.yml 文件,然后尝试 http://localhost:8888/hello-world/default 您将获得默认的空响应

    1. 因此,我们必须为 spring.cloud.config.server.native.searchLocations 使用其他一些位置,或者使用完整目录路径,或者仅使用来自应用运行位置的目录

    例子

    1. 对于 Windows 中的完整路径,请使用 file:///full-path spring.cloud.config.server.native.searchLocations: file:///E:\configs

    2. 仅用于一个目录(如果您从 IDE 运行,它将搜索项目根目录,如果运行 jar,则目标目录或 jar 位置 spring.cloud.config.server.native.searchLocations: configs spring.cloud.config.server.native.searchLocations: configs\whatever

    3. 我们也可以配置多个位置,如下 spring.cloud.config.server.native.searchLocations: file:///E:\configs, configs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2015-06-18
      • 2020-09-05
      • 2019-07-01
      • 2021-05-25
      • 2019-03-21
      相关资源
      最近更新 更多