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.
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:
- From the classpath
- The classpath root
- The classpath /config package
- From the current directory
- The current directory
- The config/ subdirectory in the current directory
- Immediate child directories of the config/ subdirectory