After some more debugging, I'm pretty much convinced that something fishy is going on so I'm taking the liberty to submit a formal issue here, since I'm not getting any relevant answer on StackOverflow.
In addition to the snippets on SO, please find attached the whole Gradle project, for your convenience.
My environment:
- macOS 11.0.1 (Big Sur)
- Spring Boot 2.4.0
$ java -version
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
Comment From: wilkinsona
Thanks for the sample. This appears to be a regression in Spring Boot 2.4.0. 2.3.5.RELEASE logs the following on startup:
2020-12-10 09:21:25.611 INFO 77998 --- [ main] compositeproperties.Application : composite-properties are : CompositeProperties(fromFirstFile={it=works}, fromSecondFile={it=works})
Whereas 2.4.0 logs the following:
2020-12-10 09:22:11.252 INFO 78203 --- [ main] compositeproperties.Application : composite-properties are : CompositeProperties(fromFirstFile={it=works}, fromSecondFile={})
Comment From: wilkinsona
With trace logging enabled, we can see that both configuration files are found and imported:
2020-12-10 10:18:33.611 TRACE 83787 --- [ main] .b.c.c.ConfigDataEnvironmentContributors : Processing imports [optional:file:./config/*/]
2020-12-10 10:18:33.611 TRACE 83787 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading file [config/second/application.yaml] using loader org.springframework.boot.context.config.StandardConfigDataLoader
2020-12-10 10:18:33.611 TRACE 83787 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading file [config/first/application.yaml] using loader org.springframework.boot.context.config.StandardConfigDataLoader
2020-12-10 10:18:33.611 TRACE 83787 --- [ main] .b.c.c.ConfigDataEnvironmentContributors : Imported 2 resource s[file [config/second/application.yaml], file [config/first/application.yaml]]```
They're then applied to the environment:
2020-12-10 10:18:33.620 TRACE 83787 --- [ main] o.s.b.c.config.ConfigDataEnvironment : Applying config data environment contributions
2020-12-10 10:18:33.620 TRACE 83787 --- [ main] o.s.b.c.config.ConfigDataEnvironment : Adding imported property source 'Config resource 'file:./config/*/application.yaml' via location 'optional:file:./config/*/''
2020-12-10 10:18:33.620 TRACE 83787 --- [ main] o.s.b.c.config.ConfigDataEnvironment : Adding imported property source 'Config resource 'file:./config/*/application.yaml' via location 'optional:file:./config/*/''
The problem is that both property sources have the same name and this results in them being considered equal. This in turns results in the second source that's added replacing the first.
Comment From: wilkinsona
@mbhave @philwebb I've pushed a possible fix but I'd like so more eyes on it before merging please.
Comment From: mbhave
Looks good to me.