Step 1: Add “snakeyaml” to maven pom.xml as a dependency
|
|
<dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>1.17</version> </dependency> |
Step 2: Define a YAML file under src/main/resources. For example, “logging.yml”
|
|
paths: logsPath: /mylogs packagePrefix: com.myapp |
Step 3: Create a LoggingConfiguration Java POJO class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import java.util.Map; public class LogConfiguration { private Map<String, String> paths; private String packagePrefix; public Map<String, String> getPaths() { return paths; } public void setPaths(Map<String, String> paths) { this.paths = paths; } public String getPackagePrefix() { return packagePrefix; } public void setPackagePrefix(String packagePrefix) { this.packagePrefix = packagePrefix; } @Override public String toString() { return "LogConfiguration [paths=" + paths + "]"; } } |
Step 4: Finally,
…
Read more ›