依赖

  1. <dependency>
  2. <groupId>org.yaml</groupId>
  3. <artifactId>snakeyaml</artifactId>
  4. <version>1.23</version>
  5. </dependency>

用法

image.png

类路径下的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);
}