// 可以使用静态代码块和属性,也可以使用非静态代码块和属性
public static String active;
static {
// 读取yml文件
ClassPathResource resource = new ClassPathResource("application.yml");
try {
// 读取properties文件
// Properties properties = PropertiesLoaderUtils.loadProperties(resource);
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(resource);
Properties properties = yaml.getObject();
active = properties.getProperty("spring.profiles.active", "prod");
}catch (Exception e) {
e.printStackTrace();
}
}