Recreate proxied @ConfigurationProperties beans on rebind#1662
Open
seonghyeoklee wants to merge 1 commit intospring-cloud:mainfrom
Open
Recreate proxied @ConfigurationProperties beans on rebind#1662seonghyeoklee wants to merge 1 commit intospring-cloud:mainfrom
seonghyeoklee wants to merge 1 commit intospring-cloud:mainfrom
Conversation
Contributor
|
Can you sign the commits so the DCO passes? |
When a @ConfigurationProperties bean is wrapped in an AOP proxy, recreate the target instance via createBean() instead of re-initializing the existing one. This ensures field initializers are restored when properties are removed from the Environment. Fixes spring-cloudgh-1616 Signed-off-by: seonghyeoklee <dltjdgur327@gmail.com>
f8fab9b to
49a9ec2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a
@ConfigurationPropertiesbean is wrapped in an AOP proxy and properties are removed from theEnvironment, callingrebind()previously left field initializers unrestored (they becamenull/0/falseinstead of their declared default values).This change modifies
ConfigurationPropertiesRebinder.rebind()so that when the bean is an AOP proxy, a fresh instance is created viacreateBean()and the proxy'sTargetSourceis replaced, ensuring field initializers are properly restored.Non-proxied beans continue to use the existing
destroyBean()+initializeBean()behavior for backwards compatibility.Fixes gh-1616
Changes
ConfigurationPropertiesRebinder: detect proxied beans and replace the proxy target with a freshly created instanceConfigurationPropertiesRebinderFieldInitializerIntegrationTeststo verify field initializer restoration