spring-cloud-commons icon indicating copy to clipboard operation
spring-cloud-commons copied to clipboard

ConfigurationPropertiesRebinder doesn't rebind properties for a bean which was created during bootstrap phase

Open pitagoras3 opened this issue 2 years ago • 0 comments

Bug description

Version of spring-cloud-commons: 3.1.5 (in lower versions of spring-cloud-commons this bug doesn't occur) Version of spring-boot: 2.7.9 (irrelevant)

When a bean using @ConfigurationProperties is created during bootstrap phase with values taken from bootstrap.yaml file, then the values of this bean's fields are not updated with properties fetched using spring-cloud.

Sample

I've created a repository which reproduces this bug: https://github.com/pitagoras3/spring-cloud-context-bug.

In this project, you can find a test SpringCloudContextBugApplicationTests.shouldNotFailToUpdateApplicationPropertiesBean which fails, when springCloudCommons version is >= 3.1.5.

Where is the problem?

After some debugging I've found out that rebind method in ConfigurationPropertiesRebinder had changed between versions 3.1.4 and 3.1.5. In my opinion the bug which I have described might be a side-effect of this specific change. In 3.1.5 version of spring-cloud-context my IncorrectProperties bean used in test is never destroyed and initialized again (as it was in version 3.1.4).

pitagoras3 avatar Mar 20 '23 13:03 pitagoras3