0

当我在 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 注释。

4

1 回答 1

1

我从堆栈跟踪中了解到的是,MercadoriaDAOOfyImpl在反序列化时会发生错误。反序列化需要类具有无参数构造函数,该构造函数是正确的,MercadoriaDAOOfyImpl并且类具有 serialVersionUID。

这里的 Java 文档:

序列化运行时将版本号与每个可序列化类相关联,称为 serialVersionUID,在反序列化期间使用该版本号来验证序列化对象的发送方和接收方是否已为该对象加载了与序列化兼容的类。如果接收者为对象加载了一个类,该对象的 serialVersionUID 与相应发送者的类不同,则反序列化将导致 InvalidClassException。可序列化的类可以通过声明一个名为“serialVersionUID”的字段来显式声明自己的serialVersionUID,该字段必须是静态的、最终的且类型为long。

我没有看到serialVersionUIDMercadoriaDAOOfyImpl所以如果它丢失了,你可以先尝试添加它,看看它是否能解决问题。

如果它在那里或者它没有解决问题,请尝试Class<T> clazzAbstractObjectifyDAO构造函数中删除参数并clazz使用反射获得,看看问题是否会解决,或者让我们看看在这种情况下会出现什么错误。

于 2013-09-20T12:45:45.190 回答