Ich versuche einfach manuell mit SnakeYAML eine dropwizard Konfigurationsdatei lesenProbleme Objekt von YAML-Datei erstellen
Mein Code sieht so aus:
FileReader reader = new FileReader("/Users/novotny/IdeaProjects/fingage-platform/config-local.yml");
Yaml yaml = new Yaml();
FingageConfiguration config = yaml.loadAs(reader, FingageConfiguration.class);
System.err.println(config);
FingageConfiguration wie folgt aussieht:
public class FingageConfiguration extends Configuration {
@Valid
@NotNull
private String env;
@JsonProperty("env")
public String getEnv() {
return env;
}
Und mein config-local.yml sieht so aus:
env: local
server:
requestLog:
timeZone: UTC
applicationConnectors:
- type: http
port: 9370
adminConnectors:
- type: http
port: 9371
Ich verstehe nicht ganz, warum Dropwizard keine Schwierigkeiten hat, ein Objekt zu konstruieren, aber ich kann es nicht mit SnakeYAML machen oder mache ich etwas falsch? Ich erhalte die folgende Fehlermeldung unter:
Exception in thread "main" Cannot create property=server for JavaBean=FingageConfiguration{server=DefaultServerFactory{applicationConnectors=[[email protected]], adminConnectors=[[email protected]], adminMaxThreads=64, adminMinThreads=1, applicationContextPath=/, adminContextPath=/}, logging=DefaultLoggingFactory{level=INFO, loggers={}, appenders=[[email protected]]}}
in 'reader', line 1, column 1:
env: "local"
^
Unable to find property 'server' on class: com.fingage.FingageConfiguration
in 'reader', line 4, column 5:
requestLog:
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:308)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189)
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:341)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450)
at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:410)
at com.fingage.service.TestYaml.main(TestYaml.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'server' on class: com.fingage.FingageConfiguration
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:132)
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:121)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:318)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:240)
... 13 more