java 读取 yml 配置 文件

引入


        
            org.yaml
            snakeyaml
            1.25
        
public String getYmlRedisPasswordValue(){
        Map obj =null;
        try {
            Yaml yaml = new Yaml();
            InputStream resourceAsStream = ShiroConfig.class.getClassLoader().getResourceAsStream("application.yml");
            obj = (Map) yaml.load(resourceAsStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map spring=(Map)obj.get("spring");
        Map redis=(Map)spring.get("redis");
        String password=(String)redis.get("password");
        return password;
    }

 

你可能感兴趣的:(java)