You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConfigurationPropertiesRebinder does not rebind removed properties for ConfigurationProperty beans #1133
The initial value of the bean MyConfigProps#myProp = 0, as it is defined at the code.
When the property changes at the environment org.jordi.my-prop=1 and the rebind is executed, the value of the bean MyConfigProps#myProp changes to 1. Which is great.
But when the same property is removed from the environment and the rebind is executed again, the value of the bean MyConfigProps#myProp remains to 1 instead of changing the value to the initial value.
Sample
See the behavior described at the following test:
@SpringBootTest(classes = ConfigurationPropertiesRebinderTestConfig.class)
@EnableAutoConfigurationclassConfigurationPropertiesRebinderTest {
@AutowiredprivateConfigurableEnvironmentenv;
@AutowiredprivateConfigurationPropertiesRebinderrebinder;
@AutowiredprivateMyConfigPropsmyConfigProps;
@Testvoidtest() {
// Value from codeassertThat(this.myConfigProps.getMyProp()).isZero();
this.addPropertyToEnvironment("org.jordi.my-prop", 1);
this.rebinder.rebind();
assertThat(this.myConfigProps.getMyProp()).isEqualTo(1);
this.removePropertyFromEnvironment("org.jordi.my-prop");
this.rebinder.rebind();
// FAILS!!!// After removing the property from tne environment, myConfigProps.getMyProp() should take the initial value from the code but it does notassertThat(this.myConfigProps.getMyProp()).isZero();
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MyConfigProps.class)
staticclassConfigurationPropertiesRebinderTestConfig {
}
@ConfigurationProperties("org.jordi")
staticclassMyConfigProps {
privateIntegermyProp = 0;
publicIntegergetMyProp() {
returnthis.myProp;
}
publicvoidsetMyProp(finalIntegermyProp) {
this.myProp = myProp;
}
}
privatevoidaddPropertyToEnvironment(finalStringname, finalObjectvalue) {
finalvarmyPropertySource = this.env.getPropertySources().get("MyEnvironment");
if (myPropertySource == null) {
finalvarpropertiesMap = newHashMap<String, Object>();
propertiesMap.put(name, value);
this.env.getPropertySources().addFirst(newMapPropertySource("MyEnvironment", propertiesMap));
} else {
((MapPropertySource) myPropertySource).getSource().put(name, value);
}
}
privatevoidremovePropertyFromEnvironment(finalStringname) {
finalvarmyPropertySource = this.env.getPropertySources().get("MyEnvironment");
if (myPropertySource != null) {
((MapPropertySource) myPropertySource).getSource().remove(name);
}
}
}
Hello, this issue also affects Maps. A key removed from the properties is not removed from the map on properties rebind. This seems to come from MapBinder.merge() that doesn't check for removed keys.
Activity
huifer commentedon Aug 30, 2022
After removal, I think it should not be reset to the default value. After removal, it should be set to null
obourgain commentedon Oct 12, 2022
Hello, this issue also affects Maps. A key removed from the properties is not removed from the map on properties rebind. This seems to come from MapBinder.merge() that doesn't check for removed keys.
david0 commentedon Nov 28, 2025
Sounds like a duplicate of #1616 to me, or at least closely related