Spring Cloud Config在運(yùn)行時(shí)刷新配置

2024-01-10 16:00 更新

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

  1. 添加Spring Boot Actuator依賴(lài)項(xiàng):

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配置類(lèi)中,以使參數(shù)在運(yùn)行時(shí)可重新加載。
  2. management.endpoints.web.exposure.include=refresh添加到application.properties中,以允許不受限制地訪問(wèn)/actuator/refresh。
  3. 使用gcloud更新屬性:

    $ gcloud beta runtime-config configs variables set \
      myapp.queue_size 200 \
      --config-name myapp_prod
  4. 發(fā)送POST請(qǐng)求到刷新端點(diǎn):

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)