引入
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
public static String getYmlRedisPasswordValue(){
Map<String,Object> obj =null;
try {
Yaml yaml = new Yaml();
InputStream resourceAsStream = Send.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");
Map<String,Object> rabbitmq =(Map<String,Object>)spring.get("rabbitmq");
String host = (String)rabbitmq.get("host");
return host;
}