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");
    }
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章