1.Spring Boot啓動會掃描以下位置的application.properties或者application.yml文件作爲Spring Boot 的默認配置文件
①: - file(項目文件):./config/
②: - file(項目文件):./
③: - classpath(resources類路徑):/config/
④: - classpath(resources類路徑):/
優先級按①②③④從高到低的順序,所有位置的文件都會被加載,高優先級配置內容會覆蓋低優先級配置的內容
spring 源碼如下:
public class ConfigFileApplicationListener
implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
private static final String DEFAULT_PROPERTIES = "defaultProperties";
// Note the order is from least to most specific (last one wins)
private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";
private static final String DEFAULT_NAMES = "application";
private static final Set<String> NO_SEARCH_NAMES = Collections.singleton(null);
/**
* The "active profiles" property name.
*/
public static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";
可以通過@value 來讀取配置了