-
Notifications
You must be signed in to change notification settings - Fork 41.2k
SpringApplication.setEnvironmentPrefix is ignored when reading SPRING_PROFILES_ACTIVE #45387
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
@philwebb, thanks for creating and analyzing this issue, especially after my unpromising false start in the original issue (bogus code snippet, no reproducer). I gather from your analysis that Spring Boot does not read all environment variables via the same single code path. Did I just "get lucky" 😉, and strike the only environment variable for which Spring Boot ignores the environment prefix? Do other configuration properties also not respect the prefix? I acknowledge that this question might not be straightforward to answer. I'm not asking you to go on a time-consuming bug hunt. Still, given the analysis that you've done for this issue, would it be quick and easy for you to search for similar telltale code that ignores the environment prefix when reading environment variables? Doing that now might avoid creating multiple similar property-specific issues in the future. Just a thought. I totally get that you might not have time for this. I'd like to set an environment prefix for my app, but the surprise discovery that Spring Boot does not (as you wrote) respect the prefix on all configuration properties spooked me. I don't want my app users to be similarly surprised. I can reduce that risk by testing the common properties that I think users are likely to use, but I'd prefer to have higher confidence that, to your (the Spring Boot developers') knowledge, Spring Boot consistently respects the prefix on all properties. (I acknowledge that "I don't want..." and "I'd prefer..." are my issues; my problems, not yours.) |
I asked:
The Spring Boot source is largely opaque to me as a newbie, so I thought I'd attempt an answer by playing Battleships and trying an "adjacent" configuration property, Boom! The environment variable This issue is interesting (at least, to me): it tells me that nobody else who sets an environment prefix is also using environment variables to set profiles. Unless others have met this bug without reporting it. This surprises me. I don't feel qualified to label profiles as "best practice" for external configuration, but they certainly offer a very flexible way of composing configurations from multiple reusable parts. Similarly, setting an environment prefix seems like a pretty good idea to me, especially for "generically" named properties such as Before encountering this bug, I would've guessed that the cool Spring Boot kids were doing both: setting an environment prefix |
See #45370 (comment) for a reproducer.
A bit of analysis shows that this line in
ConfigDataEnvironmentContributor
is creating the source, but unlikeSpringConfigurationPropertySources.adapt
it is not respecting the prefix.The text was updated successfully, but these errors were encountered: