-
Notifications
You must be signed in to change notification settings - Fork 717
Description
Bug introduced with Spring Cloud Context version: 3.0.0
When the LegacyContextRefresher is used to refresh the Spring environment properties, the temporary context created by the LegacyContextRefresher, does no longer get the defaultProperties property source propagated from the original environment.
The reason for this is because the properties method of the SpringApplicationBuilder is now used to provide the spring.cloud.bootstrap.enabled=true property to the builder. This results in the defaultProperties property source from the copied environment to be overwritten by a new property map containing only the spring.cloud.bootstrap.enabled property.
To put this in sequence (with line references to the code):
LegacyContextRefresher#updateEnvironmentget called to update the environment- It calls the
addConfigFilesToEnvironmentmethod - The
copyEnvironmentis used to copy thedefaultPropertiesandcommandLineArgsproperty sources from the environment of the real context - A
SpringApplicationBuilderis created and it gets that copied environment but also thespring.cloud.bootstrap.enabled=trueproperty via thepropertiesbuild method. - The
builder.run()is called to build the temporary context and in this method:- the environment is prepared where it configures the property sources
- here it is checked if the
SpringApplicationBuilderhas any properties - because the
spring.cloud.bootstrap.enabled=trueproperty is set on theSpringApplicationBuilderit will create a newDefaultPropertiesPropertySourceand overwrite the one from the copied environment. Thus the original default properties are lost.
The solution would be to provide the spring.cloud.bootstrap.enabled=true via other means, for instance by adding it to the default properties of the copied environment, instead of using the properties method of the SpringApplicationBuilder.