项目目录结构:
app.yaml
appid: zrunframrwork
spring:
application:
name: zrunframrwork
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/test
server:
port: 9000
测试代码
Yaml yaml = new Yaml();
//文件路径是相对类目录(src/main/java)的相对路径
InputStream in = App.class.getClassLoader().getResourceAsStream("com/zrun/TestReadYamlFile/app.yaml");//或者app.yaml
Map<String, Object> map = yaml.loadAs(in, Map.class);
String appid = map.getOrDefault("appid", "123").toString();
System.out.println(appid);
String port = ((Map<String, Object>) map.get("server")).get("port").toString();
System.out.println(port);