Describe the bug

When using Spring Cloud Config Client 4.0.3, the application gets the configuration from the config server twice: once using the "spring.profiles.active" profile and unexpectedly once more with the "default" profile (even if the spring.cloud.config.profile property has not been set)

Reverting to Spring Cloud Config Client 4.0.2 resolves the issue, and the application functions as intended, retrieving the configuration from the config server only once using the "spring.profiles.active" profile.

Application log with Spring Cloud Config Client 4.0.3 and "spring.profiles.active=dev"

Starting MainApplication using Java 17.0.7 with PID N The following 1 profile is active: "dev" Fetching config from server at : https://spring-cloud.config-server.corp.melia.services Located environment: name=springboot-service, profiles=[dev], label=null, version=3847271dbb716fe2c07464a80cb09d0a8eef9329, state=null Fetching config from server at : https://spring-cloud.config-server.corp.melia.services Located environment: name=springboot-service, profiles=[default], label=null, version=3847271dbb716fe2c07464a80cb09d0a8eef9329, state=null BeanFactory id=...

Application log with Spring Cloud Config Client 4.0.2 and "spring.profiles.active=dev"

Starting MainApplication using Java 17.0.7 with PID N The following 1 profile is active: "dev" Fetching config from server at : https://spring-cloud.config-server.corp.melia.services Located environment: name=springboot-service, profiles=[dev], label=null, version=036211d13206c76d2df12dcfddec723750b388d1, state=null BeanFactory id=...

Comment From: ryanjbaxter

This could happen now that the config client is correctly using spring config import. There will now always be a request to the config server with just the default profile in order to fetch any potential configuration that might activate additional profiles. Once Spring Boot gathers all potentially activated profiles there could be a second request in order to gather profile specific configuration.

However after this fix https://github.com/spring-cloud/spring-cloud-config/pull/2278 if the configuration is not different (ie no additional profiles are activated) then the second request will not be made.

Comment From: ipalbeniz

Thank you for bringing me up to date @ryanjbaxter!

Could you please let me know where in the documentation that working method is explained? I have read the Locating Remote Configuration Resources section, but I can't find where it explains that there will always be a request to the Config Server with the default profile.

Comment From: spekdrum

This could happen now that the config client is correctly using spring config import. There will now always be a request to the config server with just the default profile in order to fetch any potential configuration that might activate additional profiles. Once Spring Boot gathers all potentially activated profiles there could be a second request in order to gather profile specific configuration.

However after this fix #2278 if the configuration is not different (ie no additional profiles are activated) then the second request will not be made.

Hi @ryanjbaxter, the order of the requests are inverted actually. I mean, the first request is for the specific profile and the second is the default one. This is also reflected by the @ipalbeniz logs in his post. Would be the client overriding profile specific properties with the default's given this order? We experienced this behavior in an app after updating to this version.

Comment From: ryanjbaxter

@spekdrum i see that now that you point that out. Can you provide a sample that reproduces this?

Comment From: spekdrum

We just have created a new Spring Boot app v 3.1.1 with Spring Initializr with Config Client dependency.

And filled application.properties with this:

spring.config.import=configserver:https://spring-cloud.config-server.corp.melia.services
spring.profiles.active=demo

Next, started the application and curiously is accesing 3 times, first with the default, then the specific profile "demo" and finally default again :

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.1)

2023-06-27T17:17:15.480+02:00  INFO 21376 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 17.0.7 with PID 21376 (C:\Users\spekd\Downloads\demo\demo\target\classes started by spekd in C:\Users\spekd\Downloads\demo\demo)
2023-06-27T17:17:15.486+02:00  INFO 21376 --- [           main] com.example.demo.DemoApplication         : The following 1 profile is active: "demo"
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://spring-cloud.config-server.corp.melia.services
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=de10b2210a2ddf7800b2c19622eb6f6eebf0d1d4, state=null
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://spring-cloud.config-server.corp.melia.services
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[demo], label=null, version=de10b2210a2ddf7800b2c19622eb6f6eebf0d1d4, state=null
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://spring-cloud.config-server.corp.melia.services
2023-06-27T17:17:15.538+02:00  INFO 21376 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=de10b2210a2ddf7800b2c19622eb6f6eebf0d1d4, state=null
2023-06-27T17:17:16.085+02:00  INFO 21376 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=dea21cae-f540-35f1-a540-e97502b34dab
2023-06-27T17:17:16.490+02:00  INFO 21376 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.806 seconds (process running for 3.166)

Process finished with exit code 0

We tried also downgrading to 3.1.0 and it only access once, from the specific profile.

Here is the sample code: demo.zip

Comment From: ryanjbaxter

Ah yes, this is addressed by the PR I mentioned (https://github.com/spring-cloud/spring-cloud-config/pull/2278) you can try 2022.0.4-SNAPSHOT to test it out.

Comment From: ryanjbaxter

@ipalbeniz I have added some documentation explaining this in https://github.com/spring-cloud/spring-cloud-config/commit/8e090b971338899ae2b1efb51c3fff7d7a8bd61f