spring中将yaml文件转换为Properties
文章目录
- 一 ,概述
- 二,源码
一 ,概述
借助于spring框架,将yaml文件转换为Properties
二,源码
import java.util.Properties;
import org.junit.Test;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class YamlProcessBySpringTest
{
Resource resource = new ClassPathResource("application.yml");
@Test
public void testToProps()
{
YamlPropertiesFactoryBean factoryBean = new YamlPropertiesFactoryBean();
factoryBean.setResources(resource);
Properties props = factoryBean.getObject();
props.keySet().stream().forEach(k -> log.info("{} ===> {}", k, props.get(k)));
}
}
有任何问题和建议,都可以向我提问讨论,大家一起进步,谢谢!
-over-