spring-boot: No subdirectories found for mandatory directory location 'file:./config/*/' is thrown when config dir exists
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 40
- Comments: 21 (5 by maintainers)
Links to this issue
Commits related to this issue
- create example for issues https://github.com/spring-projects/spring-boot/issues/26627 — committed to gmariotti/spring-boot-bug by gmariotti 3 years ago
- 升级Spring Boot 2.5.0后,Idea启动正常。但jar启动报错java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.原因为Spring Boot的问题,待修复,相关Issues:https://github.com/spr... — committed to lWoHvYe/unicorn by lWoHvYe 3 years ago
- Revert "Gradle: Bump org.springframework.boot from 2.4.5 to 2.5.0" There is a regression reported in [1] (also reported in Spring Boot 2.4.6), preventing from leveraging a /config folder. This rever... — committed to Cosmo-Tech/cosmotech-api by rm3l 3 years ago
- Allow optional directories without sub-directories Update `StandardConfigDataLocationResolver` so that directory resources are only required when the location is not optional. Closes gh-26627 Co-au... — committed to spring-projects/spring-boot by wilkinsona 3 years ago
- Handle empty locations from patterns Update `StandardConfigDataLocationResolver` to deal with patterns when resolving empty directories. This update also fixes the handling of mandatory pattern locat... — committed to spring-projects/spring-boot by mbhave 3 years ago
- Workaround for spring-projects/spring-boot#26627 Along with this address issue about missing comment flagged by SonarQube — committed to yonadev/yona-server by Bert-R 3 years ago
- Reverted workaround for spring-projects/spring-boot#26627 — committed to yonadev/yona-server by Bert-R 3 years ago
- Bump org.springframework.boot from 2.5.0 to 2.5.1 (#695) * 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... — committed to yonadev/yona-server by dependabot[bot] 3 years ago
- Update Spring Boot because of their issue 26627 https://github.com/spring-projects/spring-boot/issues/26627 — committed to SpiNNakerManchester/JavaSpiNNaker by dkfellows 3 years ago
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:
./configspring.config.locationtooptional: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.locationshould 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_LOCATIONshould be used.Spring Boot
2.4.7and2.5.1will include all fixes that have been identified in2.4.6and2.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.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.
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
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.@snicoll Works fine with
2.4.7-SNAPSHOT. Thank you for the update 💯@johanhaleby By the time the
application.ymlis loaded,spring.config.locationwill have done its job. As written in this comment, you have to specify it with thejavacommand argument--spring.config.location=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/or the environment variableSPRING_CONFIG_LOCATION=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/.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
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.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.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.
Same problem here!