当我在 localhost 中运行应用程序时,它可以工作,但是当部署到 GAE 时,抛出以下错误:
http://myapp.appspot.com/Login
javax.servlet.ServletException: java.lang.RuntimeException: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:268)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:439)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at com.google.apphosting.runtime.SessionManagerUtil.deserialize(SessionManagerUtil.java:57)
at com.google.apphosting.runtime.jetty.MemcacheSessionStore.getSession(MemcacheSessionStore.java:39)
at com.google.apphosting.runtime.jetty.SessionManager.loadSession(SessionManager.java:327)
at com.google.apphosting.runtime.jetty.SessionManager.getSession(SessionManager.java:301)
at org.mortbay.jetty.servlet.AbstractSessionManager.getHttpSession(AbstractSessionManager.java:237)
at org.mortbay.jetty.servlet.SessionHandler.setRequestedId(SessionHandler.java:246)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:136)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
... 16 more
Caused by: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:730)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2012)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1936)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:396)
at java.util.HashMap.readObject(HashMap.java:1043)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2012)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1936)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:396)
at com.google.apphosting.runtime.SessionManagerUtil.deserialize(SessionManagerUtil.java:55)
... 25 more
Caused by: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:488)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:327)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:564)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1649)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1562)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
... 46 more
W 2013-09-19 21:44:19.795
Nested in javax.servlet.ServletException: java.lang.RuntimeException: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor:
java.lang.RuntimeException: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at com.google.apphosting.runtime.SessionManagerUtil.deserialize(SessionManagerUtil.java:57)
at com.google.apphosting.runtime.jetty.MemcacheSessionStore.getSession(MemcacheSessionStore.java:39)
at com.google.apphosting.runtime.jetty.SessionManager.loadSession(SessionManager.java:327)
at com.google.apphosting.runtime.jetty.SessionManager.getSession(SessionManager.java:301)
at org.mortbay.jetty.servlet.AbstractSessionManager.getHttpSession(AbstractSessionManager.java:237)
at org.mortbay.jetty.servlet.SessionHandler.setRequestedId(SessionHandler.java:246)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:136)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:439)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:730)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2012)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1936)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:396)
at java.util.HashMap.readObject(HashMap.java:1043)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2012)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1936)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1819)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1395)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:396)
at com.google.apphosting.runtime.SessionManagerUtil.deserialize(SessionManagerUtil.java:55)
... 25 more
Caused by: java.io.InvalidClassException: br.com.myapp.dao.MercadoriaDAOOfyImpl; no valid constructor
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:488)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:327)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:564)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1649)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1562)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
... 46 more
在 MercadoriaMbean.java 中:
public class MercadoriaMBean implements Serializable {
private MercadoriaDAO dao;
public MercadoriaMBean() {
dao = new MercadoriaDAOOfyImpl();
fillMercadorias();
}
MercadoriaDAOOfyImpl.java:
public class MercadoriaDAOOfyImpl extends AbstractObjectifyDAO<Mercadoria>
implements Serializable, MercadoriaDAO {
public MercadoriaDAOOfyImpl() {
super(Mercadoria.class);
}
AbstractObjectifyDAO.java:
public class AbstractObjectifyDAO<T extends AbstractEntity> {
private Class<T> clazz;
public AbstractObjectifyDAO(Class<T> clazz) {
this.clazz = clazz;
}
编辑
使用反射:
public AbstractObjectifyDAO(String clazz) {
ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
try {
this.clazz = (Class<T>) myClassLoader.loadClass(clazz);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
投掷错误:
java.lang.IllegalArgumentException: Class hierarchy for class br.com.myapp.model.Mercadoria has no @Entity annotation
在 AbstractObjectifyDAO.class 中:
public List<T> getAll() {
return ofy().load().type(clazz).list();
}
我检查了 Mercadoria.class 有 @Entity 注释。