引入
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
public String getYmlRedisPasswordValue(){
Map<String,Object> 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<String,Object> spring=(Map<String,Object>)obj.get("spring");
Map<String,Object> redis=(Map<String,Object>)spring.get("redis");
String password=(String)redis.get("password");
return password;
}