Spring也可以从以下位置加载配置(按优先级从高到低,高优先级的配置覆盖低优先级的配置,所有的配置会形成互补配置):
1、命令行参数:
java -jar spring-boot-02-0.0.1-SNAPSHOT.jar --server.port=8082 --server.servlet.context.path=/boot02
多个配置用空格分开;-- 配置项=值
2、来自java: comp/env的JNDI属性
3、Java系统属性(System.getProperties())
4、操作系统环境变量
5、RandomValuePropertySource配置的random.*属性值
由jar包外向jar包内进行寻找:
6、jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件
7、jar包内部的application-{profile}.properties或application.yml(带spring.profile)配置文件
加载不带profile
8、jar包外部的application-{profile}.properties或application.yml(不带spring.profile)配置文件
9、jar包内部的application-{profile}.properties或application.yml(不带spring.profile)配置文件
10、@Configuration注解类上的@PropertySource
11、通过SpringApplication.setDefaultProperties指定的默认属性