Spring-boot: spring.profiles.active incorrect override

Created on 2 Oct 2019  路  11Comments  路  Source: spring-projects/spring-boot


Spring Boot version: 2.1.7.RELEASE
Java version: 11
App server: WildFly Full 17.0.1.Final

I set spring.profiles.active via web.xml

    <context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>production</param-value>
    </context-param>

Then I want to override it and tried three ways (after read 24. Externalized Configuration

  1. ENV SPRING_PROFILES_ACTIVE=dev (I use Wildfly in Docker)
    Startup log: (ServerService Thread Pool -- 78) The following profiles are active: dev,production -- Doesn't work
  2. Then I tried via Java opts -Dspring.profiles.active=dev
    Startup log: (ServerService Thread Pool -- 84) The following profiles are active: dev,production-- Doesn't work
  3. Then I tried via JSON ENV SPRING_APPLICATION_JSON='{"spring.profiles.active":"dev"}'
    Startup log: (ServerService Thread Pool -- 82) The following profiles are active: dev -- It works!

If I right understand doc 24. Externalized Configuration, it works incorrect. Spring appended active profile instead of replace. In the first and second cases the profile should remain unchanged (stay production), but it was appended (as result dev, production). Third case was right.

Am I right?

superseded config-data profiles

All 11 comments

Thanks for the report. This is very similar to the problem described in https://github.com/spring-projects/spring-boot/issues/9972#issuecomment-333297384. https://github.com/spring-projects/spring-boot/issues/13736 is also relevant here. We'll have to see if we can further refine the ordering and time at which the servlet-related property sources are added to the environment.

This problem just bit me when upgrading from 2.1.9 to 2.2.3.

application.yaml

spring:
  profiles:
    active: local

My tests are using a profile named test:

@SpringBootTest
@ActiveProfiles("test")
@AutoConfigureMockMvc
public class MonitoringTest {

Prior to the upgrade when running the tests only the test profile was active, but now it's local,test which is reported as active.

I don't know whether this is the same cause though..

@BSchwetzel Sorry that you were bitten. That change is due to an accidental regression in 2.2.3. It'll be fixed in 2.2.4: https://github.com/spring-projects/spring-boot/issues/19821.

This seems to have been fixed in 2.4.0 snapshots. With an environment variable of SPRING_PROFILES_ACTIVE=dev and the following configuration in web.xml,

<context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>production</param-value>
</context-param>

the output was The following profiles are active: production.

Reopening since this was in the 2.2.x milestone so we should see if we still want to fix it there.

@NKozlov if you get the chance, could you try 2.4.0.M2 to see if this issue is now fixed?

@philwebb, hello!
I have checked.
Now it works correct.

Actual results for my cases (in the beginning of issue) are:

  1. ENV SPRING_PROFILES_ACTIVE=dev -> result: production (it's correct)
  2. -Dspring.profiles.active=dev -> result: production (it's correct)
  3. ENV SPRING_APPLICATION_JSON='{"spring.profiles.active":"dev"}' -> result: dev (it's correct)

Thanks for fix 馃憤

@NKozlov Thanks for testing it.

Looking at the recent conversion above, this seems to be resolved.

@izeye looking at Madhura's comment, I understand the issue was reopened to backport the fix in 2.2.x but I can see that the milestone now is wrong so I am confused. Flagging for team attention

We _think_ this issue is now fixed in 2.2.4 and 2.4.x. I'll close this one as superseded, but if the issue comes up again we can re-open.

Was this page helpful?
0 / 5 - 0 ratings