Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring.profiles.active incorrect override #18482

Closed
NKozlov opened this issue Oct 2, 2019 · 11 comments
Closed

spring.profiles.active incorrect override #18482

NKozlov opened this issue Oct 2, 2019 · 11 comments
Labels
status: superseded An issue that has been superseded by another theme: config-data Issues related to the configuration theme

Comments

@NKozlov
Copy link

NKozlov commented Oct 2, 2019

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?

@NKozlov NKozlov changed the title spring.profiles.active incorrect overrided spring.profiles.active incorrect override Oct 2, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 2, 2019
@wilkinsona
Copy link
Member

Thanks for the report. This is very similar to the problem described in #9972 (comment). #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.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 2, 2019
@wilkinsona wilkinsona added this to the 2.1.x milestone Oct 2, 2019
scottfrederick added a commit to scottfrederick/spring-boot that referenced this issue Jan 7, 2020
Prior to this commit, active profiles were being added to the Spring Boot application environment by setting the `spring.profiles.active` property. This could result in profiles getting parsed differently than other uses of `@ActiveProfiles`. Setting the profiles directly in the `Environment` prevents this parsing.

Fixes spring-projectsgh-18482
@scottfrederick scottfrederick self-assigned this Jan 7, 2020
@scottfrederick scottfrederick removed their assignment Jan 17, 2020
@BSchwetzel
Copy link

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..

@wilkinsona
Copy link
Member

wilkinsona commented Jan 20, 2020

@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: #19821.

@philwebb philwebb added theme: config-data Issues related to the configuration theme theme: profiles labels Jun 10, 2020
@philwebb philwebb modified the milestones: 2.1.x, 2.2.x Jun 10, 2020
@mbhave
Copy link
Contributor

mbhave commented Aug 6, 2020

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.

@mbhave mbhave closed this as completed Aug 6, 2020
@mbhave
Copy link
Contributor

mbhave commented Aug 6, 2020

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

@mbhave mbhave reopened this Aug 6, 2020
@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Aug 6, 2020
@philwebb philwebb modified the milestones: 2.2.x, 2.4.x Aug 14, 2020
@philwebb
Copy link
Member

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

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue and removed for: team-attention An issue we'd like other members of the team to review labels Aug 14, 2020
@NKozlov
Copy link
Author

NKozlov commented Aug 16, 2020

@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 👍

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 16, 2020
@philwebb
Copy link
Member

@NKozlov Thanks for testing it.

@izeye
Copy link
Contributor

izeye commented Aug 21, 2020

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

@snicoll
Copy link
Member

snicoll commented Aug 21, 2020

@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

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Aug 21, 2020
@philwebb
Copy link
Member

philwebb commented Aug 24, 2020

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.

@philwebb philwebb added status: superseded An issue that has been superseded by another and removed for: team-attention An issue we'd like other members of the team to review status: feedback-provided Feedback has been provided type: bug A general bug labels Aug 24, 2020
@snicoll snicoll removed this from the 2.4.x milestone Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another theme: config-data Issues related to the configuration theme
Projects
None yet
Development

No branches or pull requests

9 participants