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
True immutability with @ConfigurationProperties and @ConstructorBinding #2770
The current behavior has been reported previously here #1547.
I want to lay down the arguments why this doesn't make sense to work this way.
The current situation is that the feature works this way and is expected to work like this to achieve immutable configurations upon context refresh, in other words, those are just beans ignored by the refresh event, even if you have them marked as @RefreshScope.
The first argument against "this is how it should work" is, if I want to not refresh some properties, i.e. refresh context events are not affecting the configuration bean, I will just not put the @RefreshScope annotation.
The second argument against this statement in the original issue - "protecting jr developers during testing is not a strong enough argument for what is likely a non trivial feature to support". In my team we have had an actual production issue by the same thing.
I.e. when I think of immutability, I think of it that a single instance of bean/object is immutable. If I want it to be @RefreshScope, then I want to be able to create new bean instances with a new immutable state. If I want a bean instantiation immutability, I will just not make it part of the refresh scope event.
In simple terms I want to have the following code:
The map inside the MyConfig bean is immutable runtime. I.e. stream, filters, etc. can't modify it.
I want the map property of the MyConfig to be immutable, i.e. no setters. I don't want someone accidentally to change the map reference.
I still want to be able to update the properties on refresh application context events.
This way I am ensuring no more bugs on production from filters, streams, etc. and changed object references. I.e. true Java immutability. The way the feature is working currently I can't ever achieve true immutability of the bean's properties runtime, while still be able to update/refresh the properties
changed the title [-]True immutability with @ConfigurationProperties and @ConstructorBinding (issue #1547)[/-][+]True immutability with @ConfigurationProperties and @ConstructorBinding (reference https://github.com/spring-cloud/spring-cloud-config/issues/1547)[/+]on Feb 27, 2025
changed the title [-]True immutability with @ConfigurationProperties and @ConstructorBinding (reference https://github.com/spring-cloud/spring-cloud-config/issues/1547)[/-][+]True immutability with @ConfigurationProperties and @ConstructorBinding [/+]on Feb 28, 2025
@ryanjbaxter, on branch **5.0.x (5.0.7-SNAPSHOT), the requested behavior already works with correct bean registration — no production-code fix is necessary. See PR #3391 for details.
Activity
[-]True immutability with @ConfigurationProperties and @ConstructorBinding (issue #1547)[/-][+]True immutability with @ConfigurationProperties and @ConstructorBinding (reference https://github.com/spring-cloud/spring-cloud-config/issues/1547)[/+][-]True immutability with @ConfigurationProperties and @ConstructorBinding (reference https://github.com/spring-cloud/spring-cloud-config/issues/1547)[/-][+]True immutability with @ConfigurationProperties and @ConstructorBinding [/+]ryanjbaxter commentedon Feb 28, 2025
I am not sure this is even possible. It might be out of our control if the field is immutable. It would need to be investigated
ruthst00 commentedon Nov 9, 2026
@ryanjbaxter, on branch **5.0.x (
5.0.7-SNAPSHOT), the requested behavior already works with correct bean registration — no production-code fix is necessary. See PR #3391 for details.Confirmed that immutable config is already supported with correct bea…
Confirmed that immutable config is already supported with correct bea…
Document and test immutable configuration properties refresh: