Skip to content

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

Open
philwebb opened this issue May 7, 2025 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@philwebb
Copy link
Member

philwebb commented May 7, 2025

See #45370 (comment) for a reproducer.

A bit of analysis shows that this line in ConfigDataEnvironmentContributor is creating the source, but unlike SpringConfigurationPropertySources.adapt it is not respecting the prefix.

@GrahamHannington
Copy link

GrahamHannington commented May 8, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants