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

Allow spring.profiles.active in a config file to take effect when spring.profiles.include is configured via a higher-precedence property source #15344

Closed
facugaich opened this issue Nov 30, 2018 · 6 comments

Comments

Projects
None yet
6 participants
@facugaich
Copy link

commented Nov 30, 2018

Spring Boot version: 2.1.0.RELEASE

Summary: Setting spring.profiles.active in application.properties has no effect if system property spring.profiles.include or env var SPRING_PROFILES_INCLUDE is also set.

How to reproduce, using demo project from initializr:

application.properties
spring.profiles.active=active

Run with:
./mvnw -Dspring.profiles.include=include spring-boot:run

Expected:
The following profiles are active: include,active

But got:
The following profiles are active: include

I have also tested that the profile specific application-active.properties is not being loaded into the environment.

Setting active profiles in system properties seems to work:
./mvnw -Dspring.profiles.active=active -Dspring.profiles.include=include spring-boot:run

Output:
The following profiles are active: include,active

@philwebb

This comment has been minimized.

Copy link
Member

commented Nov 30, 2018

This is actually behaving as I would expect. The spring.profiles.active entry in your application.properties will only apply if no other profiles have been activated. When you use -Dspring.profiles.include=include this is setting a system property that will be evaluated before the application.properties file is loaded. Since the system property has activated the include profile, the spring.profiles.active property will not be used.

@facugaich

This comment has been minimized.

Copy link
Author

commented Nov 30, 2018

@philwebb Thank you

Isn't this behaviour at odds with the documentation on Profiles? More specifically:

The spring.profiles.active property follows the same ordering rules as other properties: The highest PropertySource wins. This means that you can specify active profiles in application.properties and then replace them by using the command line switch.

Sometimes, it is useful to have profile-specific properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to unconditionally add active profiles.

In a sense, they are being replaced by the higher priority spring.profiles.include property

@philwebb

This comment has been minimized.

Copy link
Member

commented Nov 30, 2018

I agree that the behavior is a little unexpected. I've reopened this one to see if we can improve things in 2.2.

@wilkinsona

This comment has been minimized.

Copy link
Member

commented Jan 16, 2019

It looks like we need to avoid setting activatedProfiles to true when recording the profiles that have been activated via the spring.profiles.include system property or environment variable. This should then allow spring.profiles.active found in an application properties file to still take effect.

@ayudovin

This comment has been minimized.

Copy link
Contributor

commented Jan 26, 2019

As far as I understand, all profiles from environment variables and files should be summarized, is it correct?

@wilkinsona

This comment has been minimized.

Copy link
Member

commented Jan 28, 2019

It's not really a matter of what is and is not summarised. My comment above was a note from an initial investigation of the problem at our recent face-to-face meeting. There's still some more work to be done to pin down exactly the right solution.

@mbhave mbhave self-assigned this Jan 28, 2019

@mbhave mbhave modified the milestones: 2.2.x, 2.2.0.M1 Feb 8, 2019

@mbhave mbhave closed this in 8528f7c Feb 8, 2019

@wilkinsona wilkinsona changed the title When spring.profiles.include is set, spring.profiles.active has no effect Allow spring.profiles.active in a config file to take effect when spring.profiles.include is configured via a higher-precedence property source Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.