Binding configuration properties to collection cannot replace individual items
See original GitHub issueThis appears to be a regression in Spring Boot 2.0 (Spring Cloud Context relies on the old behaviour for rebinding to @ConfigurationProperties when the environment changes).
Start with a @ConfigurationProperties that has a List<String> called messages, and 2 items listed in application.properties (messages[0]=one, messages[1]=two). If you add a property source to the environment with messages[0]=foo you expect to be able to rebind and get [foo, two], but failing tests are showing [foo].
I haven’t had a chance to dig into what changed. Ignored the tests for now.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
ConfigurationProperties does not bind properties
You need to remove @Component from you properties class and add setters ... bean property binding is used by @ConfigurationProperties :
Read more >Guide to @ConfigurationProperties in Spring Boot - Baeldung
A quick and practical guide to @ConfigurationProperties annotation ... a @Bean method to bind externalized properties to the Item instance:
Read more >Property Binding in Spring Boot 2.0
Since the first release of Spring Boot, it has been possible to bind properties to classes by using the @ConfigurationProperties annotation.
Read more >Configuring a Spring Boot Module with ... - Reflectoring
We might, however, want to fail startup when there is a property in the configuration file that is not actually bound to a...
Read more >Using @ConfigurationProperties in Spring Boot - amitph
Having @ConstructorBinding annotation, Spring loads the properties configurations using the provided constructor. Also, without any setter methods the state of ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m not convinced that we should encourage users to do this. Trying to override part of the configuration of a particular element of a list feels very brittle to me. If an earlier property source is changed such that a list has been reordered, or an element has been added before the one being targeted, then the configuration of the wrong item is going to be overridden. Completely overriding the contents of the list, which is now possible, is a much more robust solution and, IMO, is what we should promote.
The current behaviour of using a single source for configuring the items in a list makes completely overriding the contents of a list easy and modifying a list, albeit with some tedious repetition, possible. The old behaviour of using multiple sources makes modifying a list easy and completely overriding the contents of a list impossible.
If we’re just picking between old vs new, I think the new approach is the clear winner. If we want to spend some more effort on this I think it should be post-M1 and it should focus on trying to avoid the repetition when modifying a list without hurting the ease with which a list can be overridden. Quite how we do that, I don’t know. It’ll probably require some new syntax and require us to look through every source whenever we’re binding a list in case there’s an “additive” property configured somewhere.