springboot全局常量_springboot多环境下的自定义配置文件,并读取到常量
importorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.context.annotation.PropertySource;importorg.springframework.stereotype.Component;
@ConfigurationProperties
@PropertySource("classpath:env/${spring.profiles.active}/constant.properties")
@Component("constantProperties")public classConstantProperties {/**etl接口的地址*/
public staticString ELT_ENGINE_TRIGGER_URL;public staticString PLATFORM_SYN_URL;public staticString PLATFORM_PARAM_SYN_URL;public staticString SYN_GAME_RATE_FILE_PATH;public staticString SYN_GAME_RATE_SHELL;public static booleanIZ_PUBLISHED;//set注入把 eltEngineTriggerUrl 属性注入,然后赋值给我们定义的静态变量,完成了配置文件赋值给静态常量//set 方法一定不能是static的,不然不能注入//而且这个变量名字和properties 文件中的对应,经过测试发现不区分大小写、并会忽略下划线_符号
public voidsetEltEngineTriggerUrl(String eltEngineTriggerUrl) {
ConstantProperties.ELT_ENGINE_TRIGGER_URL=eltEngineTriggerUrl;
}public voidsetPLATFORM_SYN_URL(String platform_syn_url) {
ConstantProperties.PLATFORM_SYN_URL=platform_syn_url;
}public voidsetPlatform_param_syn_url(String platform_param_syn_url) {
ConstantProperties.PLATFORM_PARAM_SYN_URL=platform_param_syn_url;
}public voidsetSYN_GAME_RATE_FILE_PATH(String sYN_GAME_RATE_FILE_PATH) {
SYN_GAME_RATE_FILE_PATH=sYN_GAME_RATE_FILE_PATH;
}public voidsetSYN_GAME_RATE_SHELL(String sYN_GAME_RATE_SHELL) {
SYN_GAME_RATE_SHELL=sYN_GAME_RATE_SHELL;
}public voidsetIZ_PUBLISHED(String iZ_PUBLISHED) {
IZ_PUBLISHED=Boolean.parseBoolean(iZ_PUBLISHED);
}
}