springBoot通过YamlPropertiesFactoryBean读取yaml配置文件

  • public static Properties getProperties(){
       String fileName = “/application.yaml”;
     
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        try {
            //绝对路径
            //yaml.setResources(new FileSystemResource(fileName));
            yaml.setResources(new ClassPathResource(fileName));
            
        }catch (Exception e){
            
        }
        Properties properties =  yaml.getObject();
        String = properties.getProperty("key");
    }
 
 

版权声明:本文为cheng9981原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。