以下属性优先级逐渐升高(1最低,7最高)
1.通过@Configuration注解加PropertySource(“classpath:xxx.properties”)引入的外部文件中的配置属性
value1=value1-propertySource
2.通过SpringApplication类的setDefaultProperties设置的map中的属性:
package cn.edu.tju;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
public class Start {
public static void main(String[] args) {
SpringApplication springApplication=new SpringApplication(Start.class);
Map<String,Object> propertyMap=new HashMap<>();
propertyMap.put("value1","value1-setDefaultProperties");
springApplication.setDefaultProperties(propertyMap);
springApplication.run(args);
}
}
3.application.properties中配置的属性:
value1=value1-applicaton-properties
4.操作系统的环境变量中配置的属性
5.java 虚拟机的属性(System.getProperties())中获取到的属性
6.操作环境变量SPRING_APPLICATION_JSON中通过json配置的属性
7.通过java -jar xxx.jar --value1=high 这种启动jar包的方式配置的属性