Spring boot 1.X and Spring Boot 2.X do not provide the same parameters and behavior for Externalized Configuration .
A very good answer by M. Deinum relates to the features of Spring Boot 1.
I will be updating for Spring Boot 2 here.
Sources and order of environmental properties
Spring Boot 2 uses a very specific PropertySource order, which is designed to intelligently override values. Properties are considered in the following order:
Properties of global Devtools settings in your home directory (~ / .spring-boot-devtools.properties when devtools is active).
@TestPropertySource annotations on your tests.
@SpringBootTest#properties attribute of property annotation in your tests. Command line arguments.
Properties from SPRING_APPLICATION_JSON (embedded JSON embedded in an environment variable or system property).
ServletConfig initialization options.
ServletContext initialization options.
JNDI attributes from java:comp/env .
Java System Properties ( System.getProperties() ).
OS environment variables.
RandomValuePropertySource which has properties only in random order. *.
Profile-specific application properties outside your packaged jar ( application-{profile}.properties and YAML options).
Profile-specific application properties packaged inside your jar ( application-{profile}.properties and YAML options).
Application properties outside your packaged jar ( application.properties and YAML options).
Application properties packaged inside your jar ( application.properties and YAML options).
@PropertySource for your @Configuration classes. Default properties (set by setting SpringApplication.setDefaultProperties ).
To specify external properties files, these parameters should interest you:
Profile-specific application properties outside your packaged jar ( application-{profile}.properties and YAML options).
Application properties outside your packaged jar ( application.properties and YAML options).
@PropertySource for your @Configuration classes. Default properties (set by setting SpringApplication.setDefaultProperties ).
You can use only one of these 3 options or combine them according to your requirements.
For example, for very simple cases, it’s enough to use only profile-specific properties, but in other cases you can use both profile-specific properties, default properties, and @PropertySource .
Default location for application.properties files
About application.properties files (and their variants) By default, Spring loads them and adds their properties to the environment in the following order:
Top priorities are so literal:
classpath:/,classpath: /config/,file:./,file:./config/ .
How to use property files with specific names?
The default location is not always sufficient: a default location, such as the default file name ( application.properties ), may not be suitable. In addition, as in the OP question, you may need to specify several configuration files other than application.properties (and its variant).
So spring.config.name will not be enough.
In this case, you must spring.config.location explicit location using the spring.config.location environment (which is a comma-separated list of directory locations or file paths).
To be free in the file name template, add a list of file paths above the directory list.
For example, do this:
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
This method is most detailed when a folder is simply specified, but it is also a way to very accurately specify our configuration files and clearly document efficiently used properties.
spring.config.location now replaces default locations instead of adding to them
In Spring Boot 1, the spring.config.location argument adds the specified locations to the Spring environment.
But from Spring Boot 2, spring.config.location replaces the default locations used by Spring with the specified locations in the Spring environment, as documented .
When configurable custom locations are configured using spring.config.location , they replace the default locations. For example, if spring.config.location configured with the value classpath: /custom-config/ , file:./custom-config/ , the search order becomes the following:
file:./custom-config/
classpath:custom-config/
spring.config.location is now a way to ensure that any application.properties file must be explicitly specified.
For UAR JARs that should not package application.properties files, this is pretty good.
To preserve the old spring.config.location behavior when using Spring Boot 2, you can use the new spring.config.additional-location instead of spring.config.location which still adds locations, as stated in the documentation :
In addition, when custom configuration locations are configured using spring.config.additional-location , they are used in addition to the default locations.
On practice
So, suppose that, as in the OP question, you have 2 external properties files to specify and 1 properties file included in the uber jar.
To use only the configuration files you specify:
-Dspring.config.location=classpath:/job1.properties,classpath:/job2.properties,classpath:/applications.properties
To add configuration files to them in default locations:
-Dspring.config.additional-location=classpath:/job1.properties,classpath:/job2.properties
classpath: /applications.properties in the last example is not required, since the default locations have this and that the default locations here are not overwritten, but expanded.