Spring Cloud Consul은 구성을 실시간으로 동적으로 업데이트합니다.

프로젝트 주소

Github : https://github.com/fomeiherz/spring-cloud-consul-example

코드 분석

/**
 * 注解@RefreshScope必须的,实时更新配置
 */
@RefreshScope
@Configuration
public class KVConfig {
    
    

    // Consul控制台配置参数:config/spring-cloud-consul-example/timeout
    // 只能通过Getter方法获取
    @Value("${timeout:3000}")
    private Integer timeout;


    // 必须为变量声明Getter和Setter方法,否则无法实时更新变量值
    // 只能通过该方法获取配置变量
    public Integer getTimeout() {
    
    
        return timeout;
    }
    public void setTimeout(Integer timeout) {
    
    
        this.timeout = timeout;
    }
}

Consul 구성 센터 구성

여기에 사진 설명 삽입
구성을 수정할 때 1 초간 기다린 후 구성 요청시 새 구성 값이 표시됩니다.

추천

출처blog.csdn.net/fomeiherz/article/details/103525020