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

The error message when a wildcard directory location does not match any files is misleading #26415

Closed
ryanjbaxter opened this issue May 7, 2021 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@ryanjbaxter
Copy link

In my app's application.yaml I have

spring:
  config:
    import: file:/Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files/*/

The directory /Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files looks like this

~ ls -l /Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files
total 48
-rw-r--r--  1 ryanjbaxter  staff  646 May  6 21:03 application.yml
-rw-r--r--  1 ryanjbaxter  staff  483 May  6 21:02 blueorgreen.yml
-rw-r--r--  1 ryanjbaxter  staff   17 Apr 21 11:16 blueorgreenauthgateway.yml
-rw-r--r--  1 ryanjbaxter  staff   24 Apr 21 11:16 blueorgreenfrontend-local.yml
-rw-r--r--  1 ryanjbaxter  staff   86 Apr 22 13:46 blueorgreenfrontend.yml
-rw-r--r--  1 ryanjbaxter  staff  108 Apr 21 11:16 blueorgreengateway.yml

For some reason Boot thinks the directory is empty and then throws this exception

java.lang.IllegalStateException: Location 'file:/Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files/*/' must not be a pattern
	at org.springframework.util.Assert.state(Assert.java:97)
	at org.springframework.boot.context.config.LocationResourceLoader.validateNonPattern(LocationResourceLoader.java:84)
	at org.springframework.boot.context.config.LocationResourceLoader.getResource(LocationResourceLoader.java:75)
	at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolveEmptyDirectories(StandardConfigDataLocationResolver.java:247)
	at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:237)
	at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:115)
	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:101)
	at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:93)
	at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:81)
	at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:121)
	at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:242)
	at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:230)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:97)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
	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.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	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:1340)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
	at org.springframework.demo.BlueOrGreenApplication.main(BlueOrGreenApplication.java:14)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 7, 2021
@wilkinsona
Copy link
Member

As described here, your import is instructing Spring Boot to import files from every directory in /Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files/, but it only contains files so nothing is found. It would find your application.yml file if it was moved down into a sub-directory of config-files.

We might be able to improve the error a bit as I agree that it's not very clear at the moment.

@ryanjbaxter
Copy link
Author

That behavior seems odd to me. It's not would I would expect, and its not terribly clear to me in the documentation that only files in subdirectories would be picked up. So if I had files in the top level director and in subdirectories I would have to do this?

spring:
  config:
    import: file:/Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files/*/,file:/Users/ryanjbaxter/git-repos/ryanjbaxter/spring-one-tour-2021/gateway-s1p-2018/config-files/

In addition to improving the error I would also think we might be able to make the docs a bit clearer on the behavior.

@wilkinsona
Copy link
Member

Yes, that's right. If config-files/*/ picked up files in both config-files/ and in all sub-directories of config-files/, there would be no way to only pick up one or the other.

The documentation already reads quite clearly to me, particularly this sentence:

By default, Spring Boot includes config/*/ in the default search locations. It means that all subdirectories of the /config directory outside of your jar will be searched.

Reading that, it's clear to me that that config/*/ won't cause config/ to be searched.

@wilkinsona wilkinsona changed the title Using Wildcarded Directory In spring.config.import Throws IllegalStateException The error message when a wildcard directory location does not match any files is misleading May 9, 2021
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 9, 2021
@wilkinsona wilkinsona added this to the 2.4.x milestone May 9, 2021
@ryanjbaxter
Copy link
Author

OK well I guess it was just not obvious to me. Thanks for updating the error message!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants