0

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

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

4

1 回答 1

0

Posting key-value pairs to /env will trigger rebinding. Posting to /env/reset will trigger too on condition that manager propertysource not empty.

If you are not updating environment by posting /env, you can use endpoint /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)));
    }

}
于 2018-06-21T01:08:19.780 回答