-
Notifications
You must be signed in to change notification settings - Fork 41.2k
SpringApplication.setEnvironmentPrefix is ignored when reading MANAGEMENT_SERVER_PORT #45857
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
Thanks for the report. This is a regression caused, at least in part, by a performance optimisation that means that the prefix isn't considered. One option is to disable the optimization when an environment prefix has been configured but I'd like to discuss this with @philwebb as there may be a better approach. A secondary problem appears to be that the prefix isn't transferred to the child context's environment. I have yet to identify the cause. |
Rather than the prefix no longer being transferred, I believe the cause is the |
#45741 might also be related to this area. |
I've opened #45858 as 3.4.x also suffers from the second part of the problem. It's gone unnoticed as nothing binds |
I think the fix I pushed for #45741 may also solve this one. @wilkinsona If you have a sample or test could you please try it again? |
I'm struggling to reproduce it now, even with 3.5.0. Either I was/am doing something daft, or there's a subtle ordering aspect to the problem which makes me wonder if the cache is involved too somehow? I can still reproduce a failure where the property can't be bound in the child context which results in an NPE:
That's what #45858 is tracking. @emouty, given "ignored" in the issue's title, I assume that this isn't the behavior that you're seeing. Can you please share a minimal example that ignores |
you will an example on this repo https://github.com/emouty/spring-boot-issues |
Thank you, @emouty. The key piece that was missing from your original description is that you're also setting |
Indeed, I'm so used to having it here all the time that I forgot that its not the default value 😅 |
This remains the case this morning. Sorry, @philwebb. Yesterday, I was certain that I was seeing What I see now is that the wrapping is the other way around so the prefix has already been applied before We can fix the problem reported here by removing We can consider #45858 separately as the prefix not being applied to the child context's environment will still affect any configuration property binding that's performed in the child context. |
Binding in the child context does not work correctly when an environment prefix has been configured. The prefix is not applied to the child context's Environment and, therefore, prefixed environment variables are ignored during binding. We can fix the problem by reusing the parent context's ManagementServerProperties rather than binding them again in the child context. Doing so will fix the problem reported in gh-45857 that was introduced in 020fd7b and will also avoid an unnecessary second binding of the properties. gh-45858 may fix the problem more generally by applying the prefix to the child context's environment. This would benefit situations where the properties need to be bound in the child context because they haven't already been bound in the parent. Closes gh-45847
Closed by 9a1ca2f. |
In spring boot 3.4.5 I could setup my management server port as an env var with a prefix since 3.5.0 this is no longer the case. This might be due to changes from #45549
I could have
and launching my app with env var :
MYAPP_MANAGEMENT_SERVER_PORT=9090
would start management server on 9090. since 3.5.0 I need to putMANAGEMENT_SERVER_PORT=9090
to have the same behaviorThe text was updated successfully, but these errors were encountered: