0

I want to rebinding ConfigurationProperties data.Read user documentation. post http://localhost:8080/env,It working . But post http://localhost:8080/env/reset,Cannot refresh all configurations. Can only refresh keys that have visited /env. I want to refresh all the configuration what should I do?

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

xiao luo
  • 777
  • 1
  • 5
  • 6

1 Answers1

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

}
Addo Zhang
  • 356
  • 3
  • 8
  • Thanks for your reply. `/actuator/refresh` https://stackoverflow.com/questions/49311068/refreshscope-and-refresh-not-working – xiao luo Jun 21 '18 at 03:44