Spring Cloud Config在運行時刷新配置

2024-01-10 16:00 更新

Spring Cloud提供支持以使配置參數(shù)可隨向/actuator/refresh端點的POST請求重新加載。

  1. 添加Spring Boot Actuator依賴項:

Maven坐標(biāo):

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

Gradle坐標(biāo):

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
}
  1. @RefreshScope添加到Spring配置類中,以使參數(shù)在運行時可重新加載。
  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. 發(fā)送POST請求到刷新端點:

    $ curl -XPOST https://myapp.host.com/actuator/refresh
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號