以下屬性優先級逐漸升高(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配置的屬性