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;
    }
}

領事館構成センター構成

ここに画像の説明を挿入
構成を変更する場合、1秒間待機した後、構成が要求されたときに新しい構成値が表示されます。

おすすめ

転載: blog.csdn.net/fomeiherz/article/details/103525020