Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard config file locations from the working directory override each other #24428

Closed
gilles-gosuin opened this issue Dec 10, 2020 · 4 comments
Closed
Assignees
Milestone

Comments

@gilles-gosuin
Copy link

@gilles-gosuin gilles-gosuin commented Dec 10, 2020

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.

composite-properties.zip

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)

@wilkinsona
Copy link
Member

@wilkinsona wilkinsona commented Dec 10, 2020

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={})
@wilkinsona
Copy link
Member

@wilkinsona wilkinsona commented Dec 10, 2020

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.

@wilkinsona wilkinsona self-assigned this Dec 10, 2020
@wilkinsona
Copy link
Member

@wilkinsona wilkinsona commented Dec 10, 2020

@mbhave @philwebb I've pushed a possible fix but I'd like so more eyes on it before merging please.

@mbhave
Copy link
Contributor

@mbhave mbhave commented Dec 10, 2020

Looks good to me.

@philwebb philwebb modified the milestones: 2.4.x, 2.4.1 Dec 10, 2020
@philwebb philwebb closed this in 32e1289 Dec 10, 2020
@philwebb philwebb changed the title Default wildcard config file locations from the working directory do not appear to work as documented Wildcard config file locations from the working directory overrite each other Dec 10, 2020
@philwebb philwebb changed the title Wildcard config file locations from the working directory overrite each other Wildcard config file locations from the working directory override each other Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants