As long as there is a config folder in the root directory of the project, it will start to report an error

SpringBoot spring boot 2.4.6 load config error

12:30:51.961 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.
 at org.springframework.util.Assert.state(Assert.java:76)
 at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolvePatternEmptyDirectories(StandardConfigDataLocationResolver.java:268)
 at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolveEmptyDirectories(StandardConfigDataLocationResolver.java:257)
 at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolveEmptyDirectories(StandardConfigDataLocationResolver.java:248)
 at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:239)
 at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:117)
 at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$1(ConfigDataLocationResolvers.java:115)
 at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:126)
 at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:115)
 at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:107)
 at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:105)
 at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:97)
 at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:85)
 at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:121)
 at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:243)
 at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:230)
 at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
 at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
 at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
 at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
 at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
 at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
 at java.util.ArrayList.forEach(ArrayList.java:1249)
 at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
 at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
 at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
 at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318)
 at com.example.demo21.Demo21Application.main(Demo21Application.java:10)
Disconnected from the target VM, address: '127.0.0.1:57162', transport: 'socket'

Comment From: mamachanko

Running into the same issue.

This fails with the mentioned java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.:

$CWD/config/application.yaml

This works as expected:

$CWD/config/anything/application.yaml

Comment From: anoopgarlapati

Please see https://github.com/spring-projects/spring-boot/issues/26627. The issue is reported there and there are couple of workarounds provided by Spring team to unblock (Refer comment for workarounds).

Comment From: snicoll

Thanks @anoopgarlapati.

Duplicate of #26627

Comment From: mengxianglu

I still don't know how to solve it?

Comment From: snicoll

@mengxianglu this issue is closed as a duplicate as I've indicated so please follow there for workarounds. The issue has been fixed with 2.4.7 and 2.5.1 that haven't been released yet.