spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
812 stars 541 forks source link

Update misleading config watch documentation. #617

Open jkstrauss opened 4 years ago

jkstrauss commented 4 years ago

@ConstructorBinding annotated classes not refreshing I am using Spring Cloud version Hoxton with Spring Boot 2.2.x

Spring Boot 2.2.x introduced a an annotation @ConstructorBinding that allows defining @ConfigurationProperties classes strictly through constructors, which allows using immutable classes in configurations.

While the initial configuration is being loaded from my Consul K/V server, subsequent changes to the server do not get reflected in the configuration objects. The problem is not mitigated by using @RefreshScope.

spencergibb commented 4 years ago

Immutable classes are just that and are not refreshable

jkstrauss commented 4 years ago

@spencergibb I understand that the actual configuration object would not change; it is immutable. What I was expecting is that the application context would refresh, so that, for example, new HTTP requests would get a new configuration object that would reflect the new consul configuration.

The following line from the docs is what led me to believe that this would happen:

Configuration is currently read on startup of the application. Sending a HTTP POST to /refresh will cause the configuration to be reloaded. Config Watch will also automatically detect changes and reload the application context.

(https://cloud.spring.io/spring-cloud-consul/reference/html/#spring-cloud-consul-config-watch)

I tried manually refreshing the application with the /refresh endpoint, but I get the same results.

spencergibb commented 4 years ago

Refresh triggers configuration property rebinding and clears the refresh scope cache. So that statement isn't quite right

jkstrauss commented 4 years ago

@spencergibb Please elaborate. Which statement are you referring to?

spencergibb commented 4 years ago

and reload the application context.

It doesn't actually reload the application context.