Hi, I'm using external config combined with classpath config, the doc says "The list is ordered by precedence (with values from lower items overriding earlier ones)". My problem is my classpath (which consist directories like BOOT-INF META-INF and springboot things like JarLauncher) is the same directory with the current directory, so the config directory in current directory seems to be loaded as the classpath config package (not the external one). The true classpath config which located in BOOT-INF/classes/ is ignored and not loaded at all (which has some default properties like spring.application.name, so I know it's not loaded correctly because of the immediate startup error)

My solusion is put all classpath folders in a seperate directory like boot/ inside curret directory (and point the classpath to it), or rename the external config file inside the config directory to application-default.properties (which is the default profile so I don't need to add another env variables).

Is this a bug or feature?

SpringBoot Possible conflict between external config and classpath config

  1. From the classpath The classpath root The classpath /config package

  2. From the current directory The current directory The config/ subdirectory in the current directory Immediate child directories of the config/ subdirectory

Comment From: snicoll

Based on your description, it looks like you have a custom classpath setup that is causing this but I can't say for sure. If you want support, please share a minimal sample with us that we can run that reproduces what you've described. You can share it with us by attaching a zip to this issue or by pushing it to a separate GitHub repository.

Comment From: astkaasa

Here is the sample zip file. demo.zip

Run the application using org.springframework.boot.loader.JarLauncher after unzipped the jar file into the output directory using maven-antrun-plugin, only the external config file is loaded, property spring.application.name is null.

Put application.properties directly inside the resources folder or rename one of the application.properties file to application-default.properties solve the problem.

Comment From: krishna-prasad-sharma

I want to work on this issue please assign it to me

Comment From: wilkinsona

Thanks for the offer, @krishna-prasad-sharma. As indicated by the for: team-attention label, @snicoll would like to discuss this with the rest of the team. No work can be done until that has happened.

Comment From: wilkinsona

Stephane and I discussed this today and it is working as designed. I'll try to explain.

When you launch the app with java org.springframework.boot.loader.JarLauncher, the working directory is on the classpath. This is java's standard behavior when you don't specify -cp. JarLauncher then creates Boot's class loader that adds BOOT-INF/classes to the classpath. You have a config directory at both ./config/ and BOOT-INF/classes/config. With an classpath that is effectively .:BOOT-INF/classes, both of these config directories are available at classpath:config/. When something occurs multiple times of the classpath, the first occurrence wins. As a result, your configuration in ./config/ is used and your configuration in BOOT-INF/classes/config/ is ignored.

My solusion is put all classpath folders in a seperate directory like boot/ inside current directory (and point the classpath to it)

This is what I would recommend. It avoids ./config accidentally becoming unwanted classpath content.

Comment From: astkaasa

Thanks a lot. I got it. Always avoid unnecessary directories/files added to the classpath.