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

No subdirectories found for mandatory directory location 'file:./config/*/' is thrown when config dir exists #26627

Closed
gmariotti opened this issue May 21, 2021 · 21 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@gmariotti
Copy link

Hi, something changed in Spring Boot 2.4.6 and 2.5.0 when the docker image is built using Jib gradle plugin. Previously, our application was able to start without any issue with the following directories structure

/app
|_classes/ (contains the SpringBootApplication)
|_libs/
|_resources/
  |_application.yml
/config
|_ application-kubernetes.yml

but since the update, the application fails with a java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.. Any idea why?

Some extra information:

  • The docker image entrypoint is ["java", "-javaagent:newrelic/newrelic.jar", "-cp", "/app/resources:/app/classes:/app/libs/*", "com.olx.SpringBootApplicationKt"]
  • Environment variable SPRING_PROFILES_ACTIVE=kubernetes
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 21, 2021
@wilkinsona
Copy link
Member

wilkinsona commented May 21, 2021

file:./config/*/ isn't a default mandatory config location so I suspect that something must be configuring it. Given your directory structure, the error message looks correct to me as /config does not have any subdirectories. What's confusing is that I would expect this to have failed with 2.4.5 and earlier, but with a less helpful error message: #26415.

To help us to figure out exactly what's happening, can you please provide a minimal sample that reproduces the problem with 2.4.6 and that works with 2.4.5? You can share it with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 21, 2021
@Prieschl
Copy link

Prieschl commented May 21, 2021

I have the same problem since v. 2.4.6/2.5.0. It can be reproduced with a simple default project from start.spring.io (java 11, maven) by adding an empty folder "config" into the project root. It makes no difference if there actually is an application.yml file or not.
demo.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 21, 2021
@jnaalisv
Copy link

Same here; this prevents us from upgrading to 2.4.6. I managed to circumvent this by adding an empty subdirectory to /config, but that's not a preferable solution.

gmariotti added a commit to gmariotti/spring-boot-bug that referenced this issue May 21, 2021
@gmariotti
Copy link
Author

@wilkinsona created https://github.com/gmariotti/spring-boot-bug to run it in a local kubernetes cluster

@Mario-Eis
Copy link

Mario-Eis commented May 21, 2021

We are also affected by this and had to stay with version 2.4.5. We configure our application containers by mounting directories containing all config files to /config inside the individual containers.

See: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.files

Spring Boot will automatically find and load application.properties and application.yaml files from the following locations when your application starts:

  1. The classpath root
  2. The classpath /config package
  3. The current directory
  4. The /config subdirectory in the current directory
  5. Immediate child directories of the /config subdirectory

We use 4. The /config subdirectory in the current directory. So its a /config directory with only an application.yml and several other config files (log, cache,...) that are referenced inside the application.yml. No subdirectories whatsoever. There is no need for them and they would just make the whole thing unnecessary complicated. Not to speak of putting an unnecessary subdirectory in all of our container configurations.

@wilkinsona
Copy link
Member

wilkinsona commented May 21, 2021

Thanks, @Prieschl and @gmariotti, for the samples. With those I now believe I fully understand the problem.

The problem is that the default optional:file:./config/*/ search location is being treated as if it's mandatory. This branch contains a fix that I'll review with the rest of the team.

A couple of workarounds:

  1. Add an empty sub-directory to ./config
  2. Set spring.config.location to optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/.

The second option retains all the default config locations other than the one causing the problem. Note that spring.config.location should be set using an environment variable or system property so that it's picked up before configuration file processing begins. When setting it as an environment variable, SPRING_CONFIG_LOCATION should be used.

@wilkinsona wilkinsona added this to the 2.4.7 milestone May 21, 2021
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels May 21, 2021
lWoHvYe added a commit to lWoHvYe/unicorn that referenced this issue May 22, 2021
…: No subdirectories found for mandatory directory location 'file:./config/*/'.原因为Spring Boot的问题,待修复,相关Issues:spring-projects/spring-boot#26627
@johanhaleby
Copy link

johanhaleby commented May 24, 2021

We also get this error when upgrading to Spring Boot 2.5.0. Setting the "spring.config.location" to optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/ in our application.yaml file doesn't seem to work for us unfortunatley.

@Polve
Copy link

Polve commented May 24, 2021

Same problem here

@tt4g
Copy link

tt4g commented May 24, 2021

@johanhaleby By the time the application.yml is loaded, spring.config.location will have done its job.
As written in this comment, you have to specify it with the java command argument --spring.config.location=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/ or the environment variable SPRING_CONFIG_LOCATION=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/.

@yu-shiba
Copy link

yu-shiba commented May 24, 2021

This workaround will not work if spring.config.use-legacy-processing is set.
Even if you take the workaround with this set, the per-environment configuration (application-xxxx.yml or application-xxxx.properties) will be ignored.

rm3l added a commit to Cosmo-Tech/cosmotech-api that referenced this issue May 25, 2021
There is a regression reported in [1] (also reported in Spring
Boot 2.4.6), preventing from leveraging a /config folder.

This reverts commit 9f3a6d5.

[1] spring-projects/spring-boot#26627
@philwebb philwebb modified the milestones: 2.4.7, 2.4.x May 25, 2021
@philwebb philwebb self-assigned this May 25, 2021
@philwebb philwebb changed the title No subdirectories found for mandatory directory location 'file:./config/*/' since version 2.4.6 No subdirectories found for mandatory directory location 'file:./config/*/' is thrown when config dir exists May 26, 2021
@yubobo
Copy link

yubobo commented May 26, 2021

Same problem here!

@astellingwerf
Copy link

Is this fix planned for 2.5.x too? We need to upgrade to address cve-2021-22118, but this bug blocks us from upgrading.

@snicoll
Copy link
Member

snicoll commented May 31, 2021

@astellingwerf all fixes are obviously merged forward see #26672. Also, there's no need to upgrade to Spring Boot 2.5.x to benefit from the CVE fix.

@astellingwerf
Copy link

Thanks @snicoll, you're right, I mentally took a wrong turn there. Upgrading the Spring Boot Gradle plugin or Maven parent to v2.3.11.RELEASE should do the trick.

@amkuio
Copy link

amkuio commented Jun 2, 2021

Hi, something changed in Spring Boot 2.4.6 and 2.5.0 when the docker image is built using Jib gradle plugin. Previously, our application was able to start without any issue with the following directories structure

/app
|_classes/ (contains the SpringBootApplication)
|_libs/
|_resources/
  |_application.yml
/config
|_ application-kubernetes.yml

but since the update, the application fails with a java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.. Any idea why?

Some extra information:

  • The docker image entrypoint is ["java", "-javaagent:newrelic/newrelic.jar", "-cp", "/app/resources:/app/classes:/app/libs/*", "com.olx.SpringBootApplicationKt"]
  • Environment variable SPRING_PROFILES_ACTIVE=kubernetes

After upgrading Spring Boot from 2.4.5. to 2.4.6 started getting the same error. Was able to fix it by setting SPRING_CONFIG_LOCATION to optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/ in environment variable.
Thanks, @wilkinsona for the workaround. Hope this will be fixed in upcoming releases.

@snicoll
Copy link
Member

snicoll commented Jun 2, 2021

Hope the will be fixed in upcoming releases.

@amkuio you can figure that out by yourself right now by testing 2.4.7-SNAPSHOT. If that doesn't fix the problem for you, please let us know.

@JV-TMCZ
Copy link

JV-TMCZ commented Jun 2, 2021

Confirming that both 2.4.7-SNAPSHOT and 2.5.1-SNAPSHOT works. Great, thanks.

Currently I just tried
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.1-SNAPSHOT</version> </parent>

Is there a way to use only one fixed dependency in SNAPTHOT version? Instead of whole parent? which one?
When could we expect these version released?

@TaylorSMarks
Copy link

Given 2.4.5 has security issues and that 2.4.6 and 2.5.0 are both broken, it makes sense to immediately release another version.

Maybe release a 2.4.5.1 or something that fixes the security issues and does nothing else. Or release a 2.4.6.1 that just fixes this issue.

@scottfrederick
Copy link
Contributor

Spring Boot 2.4.7 and 2.5.1 will include all fixes that have been identified in 2.4.6 and 2.5.0, including this issue. You can view the project's milestones page to see what will be included in these releases. We will decide the dates for those releases in the next few days.

Given 2.4.5 has security issues

As @snicoll mentioned, you likely don't need a Spring Boot release to mitigate CVEs, as you can override the version of any dependency in your build.

philwebb referenced this issue Jun 2, 2021
Update `StandardConfigDataLocationResolver` to deal with patterns when
resolving empty directories. This update also fixes the handling of
mandatory pattern locations which would previously throw an exception.

The error message returned when a location with a pattern does not
contain any subdirectories has also been improved.

Fixes gh-26468
Fixes gh-26577
Fixes gh-26415
Bert-R added a commit to yonadev/yona-server that referenced this issue Jun 3, 2021
Along with this address issue about missing comment flagged by SonarQube
@amkuio
Copy link

amkuio commented Jun 7, 2021

Hope the will be fixed in upcoming releases.

@amkuio you can figure that out by yourself right now by testing 2.4.7-SNAPSHOT. If that doesn't fix the problem for you, please let us know.

@snicoll Works fine with 2.4.7-SNAPSHOT. Thank you for the update 💯

Bert-R added a commit to yonadev/yona-server that referenced this issue Jun 10, 2021
Bert-R added a commit to yonadev/yona-server that referenced this issue Jun 10, 2021
* Bump org.springframework.boot from 2.5.0 to 2.5.1

Bumps [org.springframework.boot](https://github.com/spring-projects/spring-boot) from 2.5.0 to 2.5.1.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](spring-projects/spring-boot@v2.5.0...v2.5.1)

---
updated-dependencies:
- dependency-name: org.springframework.boot
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Reverted workaround for spring-projects/spring-boot#26627

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bert Roos <Bert-R@users.noreply.github.com>
@borasik
Copy link

borasik commented Jun 11, 2021

Same here

dkfellows added a commit to SpiNNakerManchester/JavaSpiNNaker that referenced this issue Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests