Spring Boot 2:即时刷新属性不起作用 [英] Spring Boot 2: Refresh properties on the fly not working

查看:63
本文介绍了Spring Boot 2:即时刷新属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have followed this official tutorial Getting Started Centralized Configuration using spring boot 2.0.0.RELEASE and spring cloud Finchley.M8

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

But refreshing properties on the fly (Without restart) is not working. After Some debugging, I noticed that in method refresh() from ContextRefresher.class, it returns the changed keys correctly, but after reconstructing the bean annotated with @RefreshScope in the next use. It still sees the old value not the updated one.

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

Note: This was working perfectly with spring boot v 1.5.6 and spring cloud Edgware.RELEASE.

有什么帮助吗?

谢谢

推荐答案

似乎 spring.cloud.config.uri in spring boot 2.0.1.RELEASE 一直在寻找端口 8888 并且不接受其他值,所以我把下面的配置(您可以忽略它,因为它是客户端的默认值,并且服务器应该在端口 8888 上运行)

It seems spring.cloud.config.uri in spring boot 2.0.1.RELEASE always looking for port 8888 and not accepting other values, so I put the below configuration (you can ignore it, as it is the default value for the client, and the server should run on port 8888)

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

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

I also tried to expose all other services in the client for testing as follows

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

或使用以下仅允许刷新

management:
  endpoints:
    web:
      exposure:
        include: refresh

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

Then called POST method not GET for refreshing

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

终于成功了.

这篇关于Spring Boot 2:即时刷新属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆