-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Improve "profile" reference documentation with additional admonitions #45522
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
Comments
From a comment on an answer to the Stack Overflow question "Environment variables for list in spring boot configuration":
That comment matches the behavior that I expected. But it doesn't match the behavior I've tested in practice, in Spring Boot 3.4.5. |
This is by design and documented in https://docs.spring.io/spring-boot/reference/features/profiles.html#features.profiles.adding-active-profiles. The |
@philwebb wrote:
Thanks for the clarification, much appreciated. 👍
No, it's not. Or rather: I don't see where "Adding Active Profiles" documents this. I'd already read that "Adding Active Profiles" section before creating this issue. From that section:
Yes. I've tested this. More specifically, in the context of this issue, I've tested this with environment variables:
and, also:
No arguments there. However, I don't see anything in that section to indicate that:
I'm sincerely grateful for your time, and I don't mean to try your patience: could you please quote the specific text in that section that supports your statement "and documented in"? |
I see your point, I guess we should add a note to the "Adding Active Profiles" section to make things a little clearer. |
As discussed in earlier comments,
With apologies to any readers who feel that, given the previous statement, the following statement is the bleeding obvious:
in the sense that there is no overriding of values of Some questions:
|
How does "last wins" apply to profiles activated by multiple property sources?Perhaps this comment should be in a separate issue (reworded as a docs enhancement, e.g. "Clarify last-wins strategy for profiles activated by multiple property sources") or relegated to a question in Stack Overflow. If so, please let me know. I want to do the right thing; to not annoy anyone. From the Spring Boot docs topic "Externalized Configuration", heading "Profile Specific Files":
I've been wondering what "last wins" means when the user specifies profiles in multiple property sources; by which I mean, in the context of this issue, In briefI've done some testing. The answer: it depends! Is it worth mentioning something about this in the docs? In detailI could describe an unlikely "monster" scenario with many combinations, but let's start with some relatively simple examples that I think are realistic: Example A:
|
Perhaps there is no way to concisely encapsulate the order of all of the possible combinations. In which case: does the following Spring Boot log message reliably reflect the profile order:
? The testing that I've done so far indicates "Yes", but I don't want to just assume that. |
It's a bit of a balancing act with the documentation, we want to give enough information but also not totally overwhelm the users. I've added a few more hints that I hope will help. |
@philwebb, thanks for the docs updates. Yes, I think those hints will help. 👍 Just tying up two loose ends (I acknowledge this issue is closed)... I asked:
That question might have come across as rhetorical. It wasn't meant to be. I think the answer is "Yes". @philwebb, could you please confirm? Please let me know if you'd prefer me to ask this is as a separate question in Stack Overflow, no problem. Regarding the examples I've described, I wrote:
FYI (no action or response requested or expected; feel free to stop reading now 🙂), a fresh thought... Examples B and C break my general expectation* that, in Spring Boot, you can use environment variables to override values in configuration files (e.g. I acknowledge that this behavior is covered by the following new note:
* Re: "my general expectation", I anticipate that some readers might accuse me of conflating the "very particular" property source order with the "last-wins" profile order. I'm not. I'm aware that these orders are distinct. Here, I'm referring to the more abstract concept of user expectation of consistency across different aspects of a system's behavior. That is, in the context of "property source order", the Spring Boot docs set an expectation that environment variables override configuration files. I suspect that users will bring that expectation, as I did, to the distinct-but-related context of "profile order": that a profile activated by an environment variable should override profiles activated by configuration files. I acknowledge that the new note usefully clarifies this; resets that expectation. |
With apologies if I'm flogging a dead horse: in my opinion, example B demonstrates undesirable behavior. I think that the environment variable The remainder of this comment is draft content for user docs that I'm writing for a Spring Boot app (I've changed the example profile names and base config file name). I have mixed feelings about including the "Alternatively,..." part of the example. I'm tending toward including it because, if I were the user and I tried that, on seeing the resulting profile order, I'd probably think, "that looks like a bug to me". Thoughts? Example: Using an environment variable to add to the profiles activated by a configuration fileGiven the following properties in an spring:
profiles:
include:
- alpha
- bravo you can add to those active profiles by setting the following environment variable: export SPRING_PROFILES_ACTIVE=charlie,delta The resulting profile order contains the profiles activated by
Alternatively, you can set a export SPRING_PROFILES_INCLUDE_0=charlie
export SPRING_PROFILES_INCLUDE_1=delta In this case, the resulting profile order is different: it shows the profiles activated by the
|
Yes, See this code which calls
This is for back compatibility reasons. See #26189
We prefer to use GitHub issues only for bugs and enhancements so questions are best asked on stackoverflow.com. I'm sorry, but I don't personally have a lot of time to answer these type of questions. You may find someone from the community on stackoverflow.com who can help. |
Uh oh!
There was an error while loading. Please reload this page.
From the Spring Boot 3.4.5 docs topic "Externalized Configuration", heading "Merging Complex Types":
I interpret this to mean that, if I set the environment variable
SPRING_PROFILES_INCLUDE_0
, then that value will replace all values (all list elements) of anyspring.profiles.include
property in a configuration file.However, in practice, that's not true. In practice, the value of the environment variable
SPRING_PROFILES_INCLUDE_0
adds to the elements of thespring.profiles.include
property in a configuration file.Is this a bug, or working by design?
If it's working by design, then the docs are incorrect; or at least, misleading.
Test case
Using a "minimal" Spring Boot 3.4.5 app (e.g. the reproducer in #45370, but without setting an environment prefix).
Current working directory:
Contents of
application.yaml
:(I don't think the contents of the profile-specific files are significant here.)
Java command line to start the app:
Log excerpt:
Based on the docs, I expected only "charlie" to be active.
The text was updated successfully, but these errors were encountered: