Spring Cloud Config在运行时刷新配置

2024-01-10 16:00 更新

Spring Cloud提供支持以使配置参数可随向/actuator/refresh端点的POST请求重新加载。

  1. 添加Spring Boot Actuator依赖项:

Maven坐标:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Gradle坐标:

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
}
  1. @RefreshScope添加到Spring配置类中,以使参数在运行时可重新加载。
  2. management.endpoints.web.exposure.include=refresh添加到application.properties中,以允许不受限制地访问/actuator/refresh
  3. 使用gcloud更新属性:

    $ gcloud beta runtime-config configs variables set \
      myapp.queue_size 200 \
      --config-name myapp_prod
  4. 发送POST请求到刷新端点:

    $ curl -XPOST https://myapp.host.com/actuator/refresh
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号