Spring Boot and multiple external configuration files

To use multiple external configuration files with Spring Boot, you can use the spring.config.name property to specify the names of the configuration files. Spring Boot will look for the specified configuration files in the following locations:

  1. A file named application.properties or application.yml in the config subdirectory of the current directory.

  2. A file with the same name as the spring.config.name property in the config subdirectory of the current directory.

  3. A file with the name application.properties or application.yml in the current directory.

For example, if you want to use multiple external configuration files named config1.properties and config2.properties, you can specify the spring.config.name property as follows:

spring.config.name=config1,config2

Spring Boot will then look for the config1.properties and config2.properties files in the config subdirectory of the current directory, or in the current directory if they are not found in the config subdirectory.

You can also specify the location of the configuration files using the spring.config.additional-location property. This property allows you to specify additional directories or classpath locations where Spring Boot should look for the configuration files.

For example:

spring.config.additional-location=file:/etc/myapp/config/,classpath:/config/

This code tells Spring Boot to look for the configuration files in the /etc/myapp/config/ directory and in the config directory on the classpath.

I hope this helps! Let me know if you have any other questions.