sprinboot 配置属性
官网:Spring Boot Features(Externalized Configuration)
******************
命令行参数
命令格式
# 虚拟机参数
java -Dserver.port=8000 -jar demo.jar
java -jar -Dserver.port=8000 demo.jar
java -jar demo.jar -Dserver.port=8000
# 应用参数(在jar包后面,其余位置会报错)
java -jar demo.jar --server.port=8000
******************
命令行 json文件
命令格式
# 虚拟机参数
java -Dspring.application.json='{"my":{"name":"test"}}' -jar myapp.jar
# 应用参数
java -jar myapp.jar --spring.application.json='{"my":{"name":"test"}}'
# 与application.yml等效
my:
name: test
******************
属性文件
ConfigFileApplicationListener:springboot 2.4开始不推荐使用,2.6计划移除
@Deprecated
public class ConfigFileApplicationListener implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/*/,file:./config/";
//配置文件的默认加载目录
//目录层级加载顺序:classpath:/、classpath:/config/、
// file:./、file:./config/、file:./config/*/
//同一目录层级,先加载yml、再加载properties
//相同属性,先加载的被后加载的覆盖
private static final String DEFAULT_NAMES = "application";
//属性文件名称默认为application,如:application.yml
private static final Set<String> NO_SEARCH_NAMES = Collections.singleton((Object)null);
private static final Bindable<String[]> STRING_ARRAY = Bindable.of(String[].class);
private static final Bindable<List<String>> STRING_LIST = Bindable.listOf(String.class);
private static final Set<String> LOAD_FILTERED_PROPERTY;
public static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";
public static final String INCLUDE_PROFILES_PROPERTY = "spring.profiles.in