依赖
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
</dependency>
用法
类路径下的neo4j.yml
uri: bolt://172.26.1.78:7687
username: neo4j
password: Password_123
实体类:
@Data
public class Neo4j {
private String uri;
private String username;
private String password;
}
yaml映射成实体类:
@Test
public void shouldAnswerWithTrue() throws Exception{
Yaml yaml = new Yaml(new Constructor(Neo4j.class));
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("neo4j.yml");
Neo4j neo4j = yaml.load(stream);
System.out.println(neo4j);
}