spring 云端刷新ConfigurationProperties

spring cloud refresh ConfigurationProperties

我想重新绑定 ConfigurationProperties data.Read 用户文档。 post http://localhost:8080/env,它工作。 但是post http://localhost:8080/env/reset,无法刷新所有配置。 只能刷新访问过 /env 的键。 我想刷新所有配置怎么办?

http://projects.spring.io/spring-cloud/spring-cloud.html#_endpoints

将键值对发布到 /env 将触发 rebinding。 在 manager propertysource 不为空的情况下,发布到 /env/reset 也会触发。

如果您不通过发布更新环境 /env,您可以使用端点 /refresh

@ManagedOperation
public Map<String, Object> reset() {
    Map<String, Object> result = new LinkedHashMap<String, Object>(map);
    if (!map.isEmpty()) {
        map.clear();
        publish(new EnvironmentChangeEvent(publisher, result.keySet()));
    }
    return result;
}

@ManagedOperation
public void setProperty(String name, String value) {

    if (!environment.getPropertySources().contains(MANAGER_PROPERTY_SOURCE)) {
        synchronized (map) {
            if (!environment.getPropertySources().contains(MANAGER_PROPERTY_SOURCE)) {
                MapPropertySource source = new MapPropertySource(
                        MANAGER_PROPERTY_SOURCE, map);
                environment.getPropertySources().addFirst(source);
            }
        }
    }

    if (!value.equals(environment.getProperty(name))) {
        map.put(name, value);
        publish(new EnvironmentChangeEvent(publisher, Collections.singleton(name)));
    }

}