-
Notifications
You must be signed in to change notification settings - Fork 41k
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
Change order of spring-profiles using spring.profiles.include and active profiles #21697
Comments
Thanks for raising the issue @huehnerlady. We're planning to look at what we can do with the way that configuration properties are loaded across the board. There are quite a few legitimate use-cases like this one. Unfortunately it's quite hard for us to change the default behavior without breaking someone else who is depending on the current logic. |
There are often breaking changes in spring-boot, so I am not 100% sure why this particular one is a challenge? |
We try as much as possible to not make breaking changes in patch releases and we know from experience that fixing issues in It's not that we don't want to provide a solution, it's just I suspect we won't be able to until Spring Boot 2.4. |
That is fine, as long as it will be addressed 🙂 |
I have been searching for a simillar problem for some weeks. My two use cases:
For my use cases it would be already a solution if spring would honor an At the moment it seams to me the order the configuration properties depend only on some kind of random order of class loading. And even worse: The order seams to be different depending on if the application was built on Linux or Windows. |
Also unexpectced to me: If I have this @Configuration
@Profile("a")
@PropertySource(value = "classpath:/a.properties")
static class AProperties {
}
@Configuration
@Profile("b")
@PropertySource("classpath:/b.properties")
static class BProperties extends AProperties {
} I would expect B takes precedence over A if including (only) B. |
@bmaehr This issue is about the ordering behaviour of |
@wilkinsona I think it is perhaps not possible to solve this issue in spring-boot only, because the underlying problem is in the missing/wrong handling of order of configuration files in spring. My cases would be already solved if it is possible to define an order for the configurations with "spring.profiles.include" or active profiles. I just tried to add some more cases where order is not correct and possible solutions. |
@huehnerlady We have changed the way we process configuration files and profiles in 2.4.x. In this particular case, there are two options to get to the result you want.
We have also added support for multi-document properties files. So if you prefer to use a single
The order in which profiles are added to the environment will be determined by the ordering of the documents. Later documents will override the properties defined in earlier ones. For more details on the new processing options, please see the reference guide. Please let us know if these options work for you using the |
@mbhave Many thanks for your answer. as I want to have 2 properties files to be able to gitignore my local one I guess he second option does not work for me, unless it is possible to achieve this with The following questions came to my mind thinking about how I would use the first option
Why did you make the decision not to adapt the way spring.profiles.include works as expected, that you include the profiles not override the active profile? Having tested the first option it indeed solves my problem, but could it be that now it does ignore the I hope this feedback helps :) |
The
and define other properties in
Yes.
The imports are not necessarily tied to active profiles. Several locations can be specified under a single
Yes! A combination of |
This feels like a step down to me though. I have a private properties file which I do not check in or want to make known in the code in any way. It is my developing local properties file. So How can I then achieve the current - if imperfect - way of declaring further profiles if my developer-profile is not known in the main applications file? |
#22944 has restored the ability to use |
After being asked in #15598 to create yet another issue I am happy to do so.
Summary
I have 2 profiles with different values for properties, e.g. dev and local.
The dev properties are the properties used for our development deployment, the local properties is my local version with some tweaks to not interfere with our DEV stage.
I want to have most of the properties in "dev", but then want to override some of these properties, eg. using my local database instead of the deployed one.
so I thought I can achieve this by using
spring.profiles.include
. But this is not the case, if I use this property, all I get is the dev profiles properties.in addition you can also see that behaviour in the log, as there is the line
The following profiles are active: local,dev
I expected to see
The following profiles are active: dev, local
So what I now need to do is either to add the dev profile in my startup of the service (which is very annoying if you want to use the profile now and then not all the time, in the properties file you can just comment in/out what you need) OR copy/paste all the properties I need from dev to local (which is in my opinion an unnecessary inconvenience).
Steps to reproduce
./gradlew bootRun --args='--spring.profiles.active=local'
-> there is a log about the order of the profiles and another log to show that the valuedev.overrides.local
is true as marked in the dev profile, although the local profile says falseUsing
./gradlew bootRun --args='--spring.profiles.active=dev,local-without-dev'
you can see the behaviour I would expect using the include property.The text was updated successfully, but these errors were encountered: