Spring Cloud Consul aktualisiert die Konfiguration dynamisch in Echtzeit

Projektadresse

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

Code-Analyse

/**
 * 注解@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;
    }
}

Konfiguration des Consul-Konfigurationscenters

Fügen Sie hier eine Bildbeschreibung ein
Wenn Sie die Konfiguration ändern, wird nach 1 Sekunde Wartezeit der neue Konfigurationswert angezeigt, wenn die Konfiguration angefordert wird.

Ich denke du magst

Origin blog.csdn.net/fomeiherz/article/details/103525020
Empfohlen
Rangfolge