application.yml 文件
这个文件里面的内容是这样的
spring:
profiles:
active: dev
加载 application.yml 文件
YamlPropertiesFactoryBean yamlMapFactoryBean = new YamlPropertiesFactoryBean(); //可以加载多个yml文件 yamlMapFactoryBean.setResources(new ClassPathResource("application.yml")); Properties properties = yamlMapFactoryBean.getObject(); //获取yml里的参数 String active = properties.getProperty("spring.profiles.active"); System.out.println("active:"+active);
最后输出结果为:active:dev