【问题标题】:Spring Boot 2: Refresh properties on the fly not workingSpring Boot 2:动态刷新属性不起作用
【发布时间】:2018-08-28 00:25:27
【问题描述】:

我已经按照这个官方教程Getting Started Centralized Configuration使用spring boot 2.0.0.RELEASE和spring cloud Finchley.M8

但动态刷新属性(无需重新启动)不起作用。 经过一些调试后,我注意到在 ContextRefresher.class 的方法 refresh() 中,它正确返回了更改的键,但是在下次使用时重构了带有 @RefreshScope 注释的 bean。它仍然看到旧值而不是更新值。

注意:这与 spring boot v 1.5.6 和 spring cloud Edgware.RELEASE 完美配合。

有什么帮助吗?

谢谢

【问题讨论】:

  • 启动 2.0.0.RELEASE 有一个错误
  • 是的,我明白了。将推迟升级,直到事情稳定。谢谢

标签: spring-boot spring-cloud spring-boot-actuator


【解决方案1】:

好像spring boot 2.0.1.RELEASE中的spring.cloud.config.uri一直在寻找8888端口,不接受其他值,所以我放了下面的配置(你可以忽略它,因为它是默认值客户端,服务器应该在 8888 端口上运行

spring:
  cloud:
    config:
      uri: http://localhost:8888

我还尝试在客户端公开所有其他服务以进行如下测试

management:
  endpoints:
    web:
      exposure:
        include: '*'

或使用以下内容只允许刷新

management:
  endpoints:
    web:
      exposure:
        include: refresh

然后调用 POST 方法而不是 GET 进行刷新

$ curl -X POST localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"

终于成功了。

【讨论】:

  • 我的问题出在 2.0.0.RELEASE 版本上,也许他们在 2.0.1.RELEASE 中修复了它
  • 我在最新版本上遇到了同样的问题,但我按照上面的方法修复了它
  • 我现在尝试使用 spring boot V 2.0.0.RELEASE 在端口 8888 上运行配置服务器,问题是一样的。我认为他们设法在新版本中进行了一些修复。
【解决方案2】:

在application.properties下面使用-

management.endpoint.refresh.enabled=true
management.endpoint.restart.enabled=true
management.endpoint.health.enabled=true
management.endpoint.health.show-details=always
management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=info,health,refresh    

使用 yaml 配置文件对我不起作用,当切换到属性文件时,它可以使用上述配置。

谢谢

【讨论】:

  • 即使我尝试了同样的方法,但令人惊讶的是它对我有用。肯定是个bug
【解决方案3】:

Spring Boot 2.0 或更高版本使用“OPTIONS”方法调用“执行器/刷新”,而不是方法“POST”。

对于较低版本(

确保您在application.properties. 中定义了management.endpoints.web.exposure.include=*

【讨论】:

    猜你喜欢
    • 2014-12-30
    • 2018-11-14
    • 2021-09-30
    • 2018-12-18
    • 1970-01-01
    • 2018-08-28
    • 2016-08-06
    • 2021-06-14
    • 2019-07-16
    相关资源
    最近更新 更多