javaspringspring-bootconfiguration

How to find location of application.yml loaded by spring?


For configuring a spring boot application I can control which configuration/properties file (let's say application.yml) is loaded by placing the file in one of the locations where spring scans for such files (./config/, cwd, classpath:config/, classpath root). I can also point to a specific location using CLI (spring.config.location) or environment variables.

How can I find out where the properties file(s) was finally loaded from during runtime? I wish to check if the user specified/used his own config file or if the provided config file was used.

I am using spring 5.2.2 and springboot 2.2.2.


Solution

  • I don't know of a programmatic way of doing it, but there's a fantastic link in Spring's documentation which shows all 15(!) default property sources, including the order they are being read in, as well as the 5 locations from which property files are loaded:

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