作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
出于某种原因,我的 play eclipse 应用程序无法运行引导作业并抛出以下异常。似乎模型类 User 未编译并存储在 tmp/classes 目录中。我不确定是什么问题导致我的 play eclipse 应用程序无法在开发模式下正确编译和生成类。非常感谢任何解决方案。
----更新--------
下面是 models.User 类。这个类似乎会引起问题。每次我更改此类的源代码时, Play 都无法编译并引发以下错误。
------------models.User.java------------------------
package models;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import controllers.Secure;
import controllers.Secure.Security;
import models.deadbolt.RoleHolder;
import play.data.binding.As;
import play.data.validation.CheckWith;
import play.data.validation.Email;
import play.data.validation.Equals;
import play.data.validation.Match;
import play.data.validation.MinSize;
import play.data.validation.Password;
import play.data.validation.Required;
import play.db.jpa.Model;
import play.libs.Codec;
import play.mvc.Scope.RenderArgs;
import util.UniqueObjectCheck;
@Entity
public class User extends Model implements RoleHolder {
private static final long serialVersionUID = 1L;
@Required
public String firstname;
@Required
public String lastname;
public String gender;
@As("yyyy")
public Date dob;
@ManyToOne
public Country country;
@Required
@MinSize(8)
@Match("^[a-zA-Z0-9_]*$")
@CheckWith(UniqueUserCheck.class)
public String username;
@Required
@Equals("confirmPassword")
@MinSize(8)
@Password
public String password;
@Password
public String confirmPassword;
@Required
@Email
@Equals("confirmEmail")
@CheckWith(UniqueEmailCheck.class)
public String email;
public String confirmEmail;
public String passwordHash;
public Boolean active;
//@Required
//@OneToMany (cascade=CascadeType.ALL)
@ManyToOne (cascade=CascadeType.ALL)
public UserRole role;
/**
*
*/
public User() {
// init();
//if(role == null)
//role= new ArrayList<UserRole>();
}
public User(final String firstname, final String lastname,
final String gendre, final Date yob, final Country country,
final String username, final String password, final String email) {
super();
this.firstname = firstname;
this.lastname = lastname;
this.gender = gendre;
dob = yob;
this.country = country;
this.username = username;
this.password = password;
this.email = email;
init();
}
public User(final String firstname, final String lastname,
final String gendre, final Date yob, final Country country,
final String username, final String password,
final String confirmPassword, final String email,
final String confirmEmail) {
super();
this.firstname = firstname;
this.lastname = lastname;
this.gender = gendre;
dob = yob;
this.country = country;
this.username = username;
this.password = password;
this.confirmPassword = confirmPassword;
this.email = email;
this.confirmEmail = confirmEmail;
init();
}
public User(final String email, final String password) {
if (email == null || email.isEmpty())
throw new RuntimeException("User must have an email");
if (password == null || email.isEmpty())
throw new RuntimeException("User must have a password");
this.email = email;
// init();
}
private void init() {
passwordHash = Codec.hexMD5(password);
// BCrypt.hashpw(password, BCrypt.gensalt(saltFactor));
}
public void addRole(String name) {
if(name == null || name.isEmpty())
return;
if(hasRole(name)){
System.out.println( "user already has role: "+ name);
return;
}
this.save();
new UserRole(this,name).save();
this.save();
System.out.println( "added user role: "+ name);
}
public void encodePassword(final String password) {
passwordHash = Codec.hexMD5(password);
// BCrypt.hashpw(password, BCrypt.gensalt(saltFactor));
}
public boolean checkPassword(final String plainTextPassword) {
// BCrypt.checkpw(plainTextPassword, passwordHash);
//System.out.println(Codec.hexMD5(plainTextPassword));
return Codec.hexMD5(plainTextPassword).equals(passwordHash);
}
public static User getUserByEmail(final String email) {
return User.find("byEmail", email).first();
}
public static User getByUserName(String userName) {
return find("byUserName", userName).first();
}
public List<? extends models.deadbolt.Role> getRoles() {
List<UserRole> roles=UserRole.find("byUser", this).fetch();
System.out.println("getRoles="+roles);
return roles;
}
public boolean hasRole(final String name) {
this.save();
UserRole userRole=UserRole.getByName(name);
List<UserRole> roles=UserRole.find("byUser", this).fetch();
//System.out.print("userRole=");
//System.out.println(userRole);
return (roles.contains(userRole));
}
class UniqueEmailCheck extends UniqueObjectCheck<User> {
@Override
protected List loadExistingUniqueObjects(final User user) {
setMessage("validation.emailUsed", user.email);
return User.find("byEmail", user.email).fetch();
}
}
class UniqueUserCheck extends UniqueObjectCheck<User> {
@Override
protected List loadExistingUniqueObjects(final User user) {
setMessage("validation.used", user.username);
return User.find("byUsername", user.username).fetch();
}
}
public String toString() {
return this.username;
}
}
------models.UserRole.java------------------------
package models;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import models.deadbolt.Role;
import play.data.validation.Required;
import play.db.jpa.Model;
/**
*
*/
@Entity
public class UserRole extends Model implements Role {
@Required
public String name;
@ManyToOne
public User user;
public UserRole(User user,String name) {
this.user=user;
this.name = name;
}
public String getRoleName() {
return name;
}
public static UserRole getByName(String name) {
return UserRole.find("byName", name).first();
}
@Override
public String toString() {
return this.name;
}
}
----------------错误异常--------------------
Oops: UnexpectedException
An unexpected error occured caused by exception UnexpectedException: While applying class play.classloading.enhancers.PropertiesEnhancer on Bootstrap
play.exceptions.UnexpectedException: While applying play.CorePlugin@496614e7 on Bootstrap
at play.plugins.PluginCollection.enhance(PluginCollection.java:511)
at play.classloading.ApplicationClasses$ApplicationClass.enhance(ApplicationClasses.java:235)
at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:165)
at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at play.classloading.ApplicationClasses.getAssignableClasses(ApplicationClasses.java:67)
at play.classloading.ApplicationClassloader.getAssignableClasses(ApplicationClassloader.java:455)
at play.classloading.ApplicationClassloader$getAssignableClasses.call(Unknown Source)
at {module:crud}/app/views/tags/crud/types.tag.(line:3)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:379)
at {module:crud}/conf/routes.(line:4)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
at play.templates.Template.render(Template.java:26)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:187)
at play.mvc.Router.parse(Router.java:162)
at play.mvc.Router.parse(Router.java:190)
at play.mvc.Router.parse(Router.java:164)
at play.mvc.Router.load(Router.java:48)
at play.mvc.Router.detectChanges(Router.java:219)
at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: While applying class play.classloading.enhancers.PropertiesEnhancer on Bootstrap
at play.CorePlugin.enhance(CorePlugin.java:302)
at play.plugins.PluginCollection.enhance(PluginCollection.java:506)
at play.classloading.ApplicationClasses$ApplicationClass.enhance(ApplicationClasses.java:235)
at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:165)
at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at play.classloading.ApplicationClasses.getAssignableClasses(ApplicationClasses.java:67)
at play.classloading.ApplicationClassloader.getAssignableClasses(ApplicationClassloader.java:455)
at play.classloading.ApplicationClassloader$getAssignableClasses.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at Template_1001$_run_closure1.doCall(types.tag:6)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at Template_1001$_run_closure1.doCall(types.tag)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at groovy.lang.Closure.call(Closure.java:282)
at groovy.lang.Closure.call(Closure.java:277)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:99)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$300(GroovyCategorySupport.java:61)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:239)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:333)
at org.codehaus.groovy.runtime.dgm$723.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:307)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
at Template_1001.run(types.tag:2)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:379)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:362)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:161)
at Template_1000$_run_closure1.doCall(routes:41)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at Template_1000$_run_closure1.doCall(routes)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at groovy.lang.Closure.call(Closure.java:282)
at groovy.lang.Closure.call(Closure.java:277)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:99)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$300(GroovyCategorySupport.java:61)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:239)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:333)
at org.codehaus.groovy.runtime.dgm$723.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:307)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
at Template_1000.run(routes:2)
... 9 more
Caused by: play.exceptions.UnexpectedException: Error in PropertiesEnhancer
at play.classloading.enhancers.PropertiesEnhancer$1.edit(PropertiesEnhancer.java:175)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:197)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtBehavior.instrument(CtBehavior.java:618)
at play.classloading.enhancers.PropertiesEnhancer.enhanceThisClass(PropertiesEnhancer.java:133)
at play.CorePlugin.enhance(CorePlugin.java:297)
... 84 more
Caused by: java.lang.RuntimeException: Trying to visit uncompiled class while enhancing. Uncompiled class: models.User
at play.classloading.enhancers.Enhancer$ApplicationClassesClasspath.openClassfile(Enhancer.java:75)
at javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:335)
at javassist.ClassPool.openClassfile(ClassPool.java:594)
at javassist.CtClassType.getClassFile2(CtClassType.java:185)
at javassist.CtClassType.makeFieldCache(CtClassType.java:760)
at javassist.CtClassType.getMembers(CtClassType.java:751)
at javassist.CtClassType.getDeclaredField2(CtClassType.java:873)
at javassist.CtClassType.getField2(CtClassType.java:828)
at javassist.CtClassType.getField(CtClassType.java:820)
at javassist.expr.FieldAccess.getField(FieldAccess.java:113)
at play.classloading.enhancers.PropertiesEnhancer$1.edit(PropertiesEnhancer.java:140)
... 89 more
最佳答案
看起来您的代码无法编译,并且您正在尝试以生产模式启动。在您的项目中运行 play eclipsify 并将其重新导入到 eclipse 中。
解决任何可能的编译错误。
还要确保应用程序在您的 application.conf 中以开发模式 application.mode=dev 启动
关于playframework 未编译类同时增强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136382/
我是一名优秀的程序员,十分优秀!