我正在用Java编写Play 2.3.2应用程序。
我有一个角色类,如下所示:
public class Role {
private String name;
private ArrayList<String> create;
private ArrayList<String> read;
private ArrayList<String> update;
private ArrayList<String> delete;
private ArrayList<String> pages;
private ArrayList<String> modules;
private List<String> modulesAuth;
public Role(String name, ArrayList<String> create, ArrayList<String> read,
ArrayList<String> update, ArrayList<String> delete, ArrayList<String> modules,
List<String> modulesAuth) {
super();
this.name = name;
this.create = create;
this.read = read;
this.update = update;
this.delete = delete;
this.modules = modules;
this.modulesAuth = modulesAuth;
this.pages = null;
}
public boolean canCreate(String resourceName) {
if (create == null)
return false;
return create.contains(resourceName);
}
public boolean canDelete(String resourceName) {
if (delete == null)
return false;
return delete.contains(resourceName);
}
public boolean canRead(String resourceName) {
if (read == null)
return false;
return read.contains(resourceName);
}
public boolean canUpdate(String resourceName) {
if (update == null)
return false;
return update.contains(resourceName);
}
public ArrayList<String> getCreate() {
return create;
}
public ArrayList<String> getDelete() {
return delete;
}
public List<String> getModules() {
return modules;
}
public List<String> getModulesAuth() {
return modulesAuth;
}
public String getName() {
return name;
}
public ArrayList<String> getPages() {
return pages;
}
public ArrayList<String> getRead() {
return read;
}
public ArrayList<String> getUpdate() {
return update;
}
public void setCreate(ArrayList<String> create) {
this.create = create;
}
public void setDelete(ArrayList<String> delete) {
this.delete = delete;
}
public void setModules(ArrayList<String> modules) {
this.modules = modules;
}
public void setModulesAuth(List<String> modulesAuth) {
this.modulesAuth = modulesAuth;
}
public void setName(String name) {
this.name = name;
}
public void setPages(ArrayList<String> pages) {
this.pages = pages;
}
public void setRead(ArrayList<String> read) {
this.read = read;
}
public void setUpdate(ArrayList<String> update) {
this.update = update;
}
}
我的yml文件如下所示:
roles:
- !!bdrim.models.Role
name: Super Administrator
create:
- users
- companies
- roles
- pages
- company users
- company shops
read:
- users
- companies
- roles
- pages
- company users
- company shops
- company charts
- modules
update:
- users
- companies
- roles
- pages
- company users
- company shops
delete:
- users
- companies
- roles
- pages
- company users
- company shops
modules:
- mailchimp
- recommendation system
modulesAuth:
- mailchimp
- recommendation system
pages:
- users
- companies
- roles
- pages
- company users
- company shops
- company charts
我的Global
类称为此yml文件。
但是当我尝试启动服务器时发生了异常:
[error] application -
! @6k0h3h3fp - Internal server error, for (GET) [/modules] ->
play.api.UnexpectedException: Unexpected exception[ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:bdrim.models.Role; exception=java.lang.NoSuchMethodException: bdrim.models.Role.<init>(); in 'reader', line 132, column 7:
- !!bdrim.models.Role
^]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:151) ~[play_2.11-2.3.2.jar:2.3.2]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:115) ~[play_2.11-2.3.2.jar:2.3.2]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.2.jar:na]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:115) ~[play_2.11-2.3.2.jar:2.3.2]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:113) ~[play_2.11-2.3.2.jar:2.3.2]
Caused by: org.yaml.snakeyaml.constructor.ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:bdrim.models.Role; exception=java.lang.NoSuchMethodException: bdrim.models.Role.<init>(); in 'reader', line 132, column 7:
- !!bdrim.models.Role
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:336) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:275) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:246) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:442) ~[snakeyaml-1.13.jar:na]
Caused by: org.yaml.snakeyaml.error.YAMLException: java.lang.NoSuchMethodException: bdrim.models.Role.<init>()
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:219) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:332) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:275) ~[snakeyaml-1.13.jar:na]
Caused by: java.lang.NoSuchMethodException: bdrim.models.Role.<init>()
at java.lang.Class.getConstructor0(Class.java:2810) ~[na:1.7.0_55]
at java.lang.Class.getDeclaredConstructor(Class.java:2053) ~[na:1.7.0_55]
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:215) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189) ~[snakeyaml-1.13.jar:na]
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:332) ~[snakeyaml-1.13.jar:na]
出了什么问题?
当我跳过yml
的模块部分时,一切正常。