我試圖在play1.2.4中將端口轉移到YABE以播放2.0.4 Java。對於我創建了一個初始data.yml並試圖Global.java加載它在播放2.0時加載initial-data.yml時出現問題
#Users users: - !!models.User email: [email protected] password: secret fullname: Bob isAdmin: true #Posts posts: - !!models.Post id: 1 title: About the model layer postedAt: 2009-06-14 author: - !!models.User email: [email protected] content: > The model has a central position in a Play! application. Cut....
我Global.java低於
public void onStart(Application app) {
InitialData.insert(app);
}
static class InitialData {
public static void insert(Application app) {
if(Ebean.find(User.class).findRowCount() == 0) {
Map<String, List<Object>> all = (Map<String, List<Object>>)Yaml.load("initial-data.yml");
Ebean.save(all.get("users"));
Ebean.save(all.get("posts"));
Ebean.save(all.get("comments"));
}
}
}
加載時我收到以下錯誤
ConstructorException:null;無法爲標記構造java對象:yaml.org,2002:models.Post; exception =不能爲JavaBean = [email protected]創建property = author;有3個參數沒有合適的構造函數發現類models.User
org.yaml.snakeyaml.constructor.ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:models.Post; exception=Cannot create property=author for [email protected]; No suitable constructor with 3 arguments found for class models.User org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:333) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:277) org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:248) org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:440) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:326) org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:143) org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:307) org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:459) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:142) org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:128) org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
任何想法,爲什麼出現這種情況?
我認爲' - '說「列表中的元素」 – Maxence