-
Notifications
You must be signed in to change notification settings - Fork 8.9k
bugfix: ensure environment is fully loaded before ConfigurationFactory initialization #7705
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
base: 2.x
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #7705 +/- ##
============================================
+ Coverage 61.38% 61.42% +0.03%
- Complexity 684 688 +4
============================================
Files 1323 1323
Lines 49943 49941 -2
Branches 5885 5884 -1
============================================
+ Hits 30657 30675 +18
+ Misses 16524 16508 -16
+ Partials 2762 2758 -4
🚀 New features to boost your workflow:
|
ObjectHolder.INSTANCE.setObject( | ||
OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT, applicationContext.getEnvironment()); | ||
} | ||
ObjectHolder.INSTANCE.setObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT, environment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this change was made?
What's the difference between setting the environment only when it's empty and setting it unconditionally (without checking for emptiness)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@funky-eyes Thanks for the review!
The key point: Line 64 triggers ConfigurationFactory
static initialization, which needs a complete environment.
With the old null check:
EnvironmentPostProcessor
sets environment (without application.properties in Spring Cloud)ApplicationContextInitializer
skips updating (due to null check)ConfigurationFactory
gets incomplete environment → can't readseata.config.type
from application.properties
Unconditional update ensures:
- Always use
ApplicationContextInitializer
's environment (which has all property sources loaded) - Safe because it's always more complete than
EnvironmentPostProcessor
's
This explains why bootstrap.yml workaround works - it's loaded early enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, in Spring Cloud there can be multiple Environment instances, which is why the environment may be incomplete. Otherwise, as I understand it, the same instance shouldn't have this problem, right?
fixes: #7641
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews