【Spring Cloud】02-Config

配置刷新三要素
pom依赖中有spring-boot-starter-actuator


   org.springframework.boot
   spring-boot-starter-actuator

在bootstrap.yml添加如下配置,暴露/actuator/refresh 端点:

# 暴露监控端点
management:
  endpoints:
    web:
      exposure:
        include: '*'

待刷新的配置属性所在的类上添加了@RefreshScope注解 ,例如:

@RestController
@RefreshScope
public class ConfigClientController {
  @Value("${profile}")
  private String profile;

  @GetMapping("/profile")
  public String hello() {
    return this.profile;
  }
}

修改profile 配置后,只需向应用的/actuator/refresh 端点发送POST请求,即可刷新该属性。例如:

curl -X POST http://localhost:8082/actuator/refresh

你可能感兴趣的:(【Spring Cloud】02-Config)