Describe the bug If I use spring-boot-starter-parent = 2.4.8 vs 2.5.2 then I can't read spring.profiles.active from the Config Server's files When running with application.properties with a value of spring.profiles.default=local it connects to the config server and reads both properties files:

==> src/main/resources/config/config-client-local.properties <==
readProfile=ConfigServerReadActiveProfile-Local

==> src/main/resources/config/config-client.properties <==
readProfile=ConfigServerReadActiveProfile
spring.profiles.active=${readProfile}

And the client outputs
The following profiles are active: ConfigServerReadActiveProfile-Local But if I switch to 2.5.2 (or 2.5.0, 2.5.1) I get No active profile set, falling back to default profiles: local

Was this an intended change?

Example config-server-client-active-profile.zip

Run first the server mvn spring-boot:run -f config-server/pom.xml then the client mvn spring-boot:run -f config-client/pom.xml As packaged you will see the No active profile set message, if you edit the spring-boot-starter-parent version in the root pom and run the client again, you will get the The following profiles are active message

Comment From: jaganm2018

Can you please try with this spring.config.activate.on-profile=default

Comment From: bgiaccio

I tried adding spring.config.activate.on-profile=default in 2 places. First in config-client/src/main/resources/application.properties, it fails quickly never connecting to the config server with this error

[main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.boot.context.config.InactiveConfigDataAccessException: Inactive property source 'Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'' imported from location 'class path resource [application.properties]' cannot contain property 'spring.profiles.default' [origin: class path resource [application.properties] - 2:25]
    at org.springframework.boot.context.config.InactiveConfigDataAccessException.throwIfPropertyFound(InactiveConfigDataAccessException.java:126)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributors$InactiveSourceChecker.onSuccess(ConfigDataEnvironmentContributors.java:315)
    at org.springframework.boot.context.properties.bind.Binder.handleBindResult(Binder.java:351)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:341)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:329)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:259)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:220)
    at org.springframework.boot.context.config.Profiles.getProfiles(Profiles.java:101)
    at org.springframework.boot.context.config.Profiles.getDefaultProfiles(Profiles.java:92)
    at org.springframework.boot.context.config.Profiles.<init>(Profiles.java:83)
    at org.springframework.boot.context.config.ConfigDataEnvironment.withProfiles(ConfigDataEnvironment.java:275)
    at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:231)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
    at org.example.config.client.ConfigClientApplication.main(ConfigClientApplication.java:10)

So I removed it from there and tried putting it in config-server/src/main/resources/config/config-client.properties, then in the config-server logs I see this when the client connects:

2021-06-29 08:34:55.441  WARN 27657 --- [nio-8888-exec-1] o.s.c.c.s.e.EnvironmentController        : Error getting the Environment with name=config-client profiles=local label=null includeOrigin=true

org.springframework.cloud.config.server.environment.FailedToConstructEnvironmentException: Could not construct context for config=config-client profile=local label=null includeOrigin=true; nested exception is org.springframework.boot.context.config.InactiveConfigDataAccessException: Inactive property source 'Config resource 'class path resource [config/config-client.properties]' via location 'classpath:/config/'' imported from location 'class path resource [config/config-client.properties]' cannot contain property 'spring.profiles.active' [origin: class path resource [config/config-client.properties] - 2:24]
    at org.springframework.cloud.config.server.environment.NativeEnvironmentRepository.findOne(NativeEnvironmentRepository.java:158) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository.findOne(CompositeEnvironmentRepository.java:64) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at org.springframework.cloud.config.server.environment.EnvironmentEncryptorEnvironmentRepository.findOne(EnvironmentEncryptorEnvironmentRepository.java:61) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at org.springframework.cloud.config.server.environment.EnvironmentController.getEnvironment(EnvironmentController.java:131) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at org.springframework.cloud.config.server.environment.EnvironmentController.defaultLabelIncludeOrigin(EnvironmentController.java:113) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]

Same errors if I use 2.4.8 or 2.5.2

Comment From: suniram

I'm experiencing the same issue, the spring.profiles.active is not loaded from config server. This worked perfectly on 2.4.6

Comment From: nayestaran

I'm experiencing the same issue. I've tried defining the active profile using the env variable SPRING_PROFILES_ACTIVE but does not work either. The SPRING_PROFILES_ACTIVE variable worked perfectly on 2.4.2

Comment From: aleytonredwood

I'm experiencing the same issue. It work on 2.5.1 but when upgrade to 2.5.2 or 2.5.3 fail even if set the property as VM arg or ENV arg

Comment From: oliver-schwab

Same issue here after upgrading von 2.4.9 to 2.5.x. Anyone found a solution yet?

Comment From: kishorejannarapu

I am also facing the same issue on spring-boot 2.5.x. But it is working on 2.4.x. Without this option, we have to duplicate the profile activation codes on each client, which is painful.

Comment From: sabyasachi10

Hi, In Springboot 2.5.X version, it doesn't activate the active profile. As a solution, I have added below code in springboot application main class and it got resolved.

@ Override public void onStartup(ServletContext servletContext) throws ServletException { System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "profile"); super.onStartup(servletContext); }

Comment From: mehiel

Same. Isn't this pretty huge to be ignored?

Comment From: infa-annus

@mehiel I agree. My team has been waiting on this to be resolved for a couple of months now.

Comment From: real-malan

can we get any update regarding this issue?

Comment From: dineshosharma

Setting below profile property did not work for 2.5.X, 2.6.6 and 2.6.7 version of spring boot.

@ Override public void onStartup(ServletContext servletContext) throws ServletException { System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "profile"); super.onStartup(servletContext); }

This issue can be fixed by adding active profile during startup or using conditional property as below.

1) Interject active profile during startup e.g

mvn spring-boot:run -f config-client/pom.xml -Dspring-boot.run.profiles=ConfigServerReadActiveProfile-Local

2) Or, update bean profile to use conditional property.

From: @Profile(value="ConfigServerReadActiveProfile-Local")

To: @ConditionalOnProperty(name="readProfile", havingValue="ConfigServerReadActiveProfile-Local")

Comment From: mstarodubtsev

I faced with the same issue as well. Any idea when this might be fixed? spring-boot 2.7.7.

Comment From: ryanjbaxter

@mstarodubtsev could you provide an updated sample?

Comment From: spring-cloud-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: bgiaccio

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Which requested information would that be?
When I created the bug I gave you a sample illustrating the problem. Back in June of 2021 I was asked to try something, I did and posted the results and never received a reply. Most of the other comments on this bug are when will this be fixed and me too.

I wound up converting all our code to use ConditionalProperty as a few people suggested but it it isn't nearly as clean or elegant as using the profiles as intended.

Comment From: ryanjbaxter

What was your code using before you switched to @ConditionalOnProperty?

Comment From: bgiaccio

What was your code using before you switched to @ConditionalOnProperty?

Was that directed to me? It was using spring profiles indicated by the config server. As seen in the code attached to the ticket.

Comment From: ryanjbaxter

@bgiaccio yes it was sorry

In your sample I only see you printing what the value of readProfile was. I did not see any code activating components based on the active profile. Were you using @Profile and now have switched to @ConditionalOnProperty?

Comment From: bgiaccio

The code was a sample we had dozens of config classes and beans based on the profile. The code demonstrates what happens when the list of profiles doesn't come from the config server like it used to.

To be able to upgrade spring all that code has since been converted to conditional properties.

But it is much harder for a junior developer to understand the nature of what was before a simple Profile("!UseSomeService") when instead written as Conditional property that has to check if a string is or isn't in a list of values that has to get split.

So the ask of the bug was to tell me if I was doing something wrong or revert the change or offer alternatives.

Comment From: JavatechWorld

Did anyone check this ? Is it working ?

Comment From: ryanjbaxter

It should be, yes