Our Spring Boot applications use spring.config.import=configserver:http://config:8081 where config is the service name resolved automatically when deployed in a system like Docker Swarm or Kubernetes. In local systems, we override this property with the environment variable SPRING_CONFIG_IMPORT with configserver:http://localhost:8081. Using Spring Boot 2.7.6 and Spring Cloud Config 2021.0.1, it is working as expected. When we change the Spring Cloud version to 2021.0.2, the application tries to load the properties from both http://config:8081 and http://localhost:8081.
I tried debugging the issue in the ConfigData* classes, and it seems like both URLs, are resolved in the client application side by Spring Boot which is why I have raised this in the Spring Boot project instead of Spring Cloud Config.
A sample reproducer is provided with branches for both working and non-working version combinations.
Comment From: sravaniv-3cortex
I tried this after upgrading to Spring Boot 3 and Spring Cloud 2022.0.0-RC3, and the result was the same.
Comment From: mhalbritter
Thanks for the report, something is wrong here.
Comment From: sravaniv-3cortex
Thanks. One more thing I observed is this got introduced in 2.6.7.
Comment From: philwebb
It should not be possible to override spring.config.import properties with environment variables and I'm surprised this ever worked. Trying the 2.6.7-2021.0.2 branch of your sample I get an java.net.UnknownHostException: config error even if I have a SPRING_CONFIG_IMPORT environment variable set to configserver:http://localhost:8081.
It really doesn't make to allow spring.config.location values to be overridden since those values are processed as files are loaded.
I'm not sure if there's a recommended way to do what you need. @spencergibb might have some suggestions.
One thing that does appear to work is to use a placeholder for the server. E.g. change your application.properties to
confighost=http://config:8081
spring.config.import=configserver:${confighost}
Then set a CONFIGHOST environment variable to override it.
Comment From: philwebb
I'm going to close this one here since I don't think there's a bug in Spring Boot.
Comment From: sravaniv-3cortex
@philwebb Thanks for the clarification. Seems like this is a bug in <=2.6.6 and we have been using it as a feature as the behaviour I had mentioned with works with 2.6.6. We will proceed with your approach of CONFIGHOST.