A. The configuration file load order
SpringBoot application.properties scans files as well as several locations application.yml file as Springboot default configuration files, and different locations will cause different load priority documents.
File locations are as follows:
-file:./config/
-file:./
-classpath:/config/
-classpath:/
Writes by the port number in the configuration file access, and determines the load order different profiles.
Limited two principles:
1. Priority loading a configuration file in the file directory
2. Priority loading a configuration file in the config directory
SpringBoot will load all the configuration files from the four position, between complementary profiles.
II. Loading external configuration files
If you do not want to use the file as application.properties application.yml or profiles, the following code may be used to load the configuration file
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
or
java -jar -Dspring.config.location=D:\config\config.properties springbootrestdemo-0.0.1-SNAPSHOT.jar
You may be directly arranged in code @PropertySource
@SpringBootApplication @PropertySource(value={"file:config.properties"}) public class SpringbootrestdemoApplication { public static void main(String[] args) { SpringApplication.run(SpringbootrestdemoApplication.class, args); } }