Describe the bug
Starting with Spring Cloud Config 4.0.3, Spring profile-specific settings of spring.cloud.config.uri
are ignored.
Sample
To reproduce the problem, follow these steps:
- Checkout Spring Cloud Config v4.0.2
git clone https://github.com/spring-cloud/spring-cloud-config.git
cd spring-cloud-config
git checkout v4.0.2
- Start the sample config server:
cd spring-cloud-config-server
../mvnw spring-boot:run
- In a separate terminal, verify that the config server works
curl localhost:8888/foo/development -s | jq
- Remove all property files in the folder
spring-cloud-config-sample/src/main/resources
and addapplication.yml
with the following content:
spring.config.import: "configserver:"
spring.application.name: bar
spring.cloud.config.uri: http://configserver:8888/
---
spring.config.activate.on-profile: localtest
spring.cloud.config.uri: http://localhost:8888/
- Start the sample config client, using the Spring profile
localtest
:
cd spring-cloud-config-sample
SPRING_PROFILES_ACTIVE=localtest ../mvnw spring-boot:run
- In a separate terminal, verify that the sample config client works
curl "localhost:8080/?q=foo"
# Expect the response: "bar2"
# Stop the config-client
CTRL/C
Note: This proves that the config client picks up spring.cloud.config.uri
(http://localhost:8888/) from the active profile, localtest
!
- Checkout v4.0.3 and rerun the tests of the sample config client:
git checkout v4.0.3
SPRING_PROFILES_ACTIVE=localtest ../mvnw spring-boot:run
Note: The config client will now fail with the error: Caused by: java.net.UnknownHostException: configserver
, since it ignores the setting SPRING_PROFILES_ACTIVE=localtest
Note: As a workaround, the explicit URL to the config serfver can be specified when starting the config client:
SPRING_CLOUD_CONFIG_URI=http://localhost:8888 SPRING_PROFILES_ACTIVE=localtest ../mvnw spring-boot:run
Comment From: ryanjbaxter
The version of Spring Cloud you are using is no longer supported. Can you please and try and reproduce this problem with Spring Cloud 2023.0.5 or Spring Cloud 2024.0.0?
Comment From: magnus-larsson
Yes!
I'm sorry for being unclear. I intended to show in which version the issue was introduced, i.e., v4.0.3.
I failed to mention that the error remains in the main branch.
To verify for Spring Cloud 2023.0.5 and Spring Cloud 2024.0.0, replace git checkout v4.0.3
in the instruction above with git checkout v4.1.5
and git checkout v4.2.0
.