Appengine Java:NotSerializableException

时间:2013-05-21 14:15:52

标签: java google-app-engine exception serialization

我在GAE Java中开发了一个应用程序,但是我只在部署版本上收到错误,我无法在本地环境中改善这种情况。

当我调用我已经创建的servlet时,该过程结束时没有任何错误(我记录了很多所有过程以解决此问题)。 servlet打印响应输出,然后代码完成。

但是在此过程之后我收到以下错误,因此客户端收到的真实响应是经典的错误500页面。

java.lang.RuntimeException: java.io.NotSerializableException: java.util.logging.Logger
    at com.google.apphosting.runtime.SessionManagerUtil.serialize(SessionManagerUtil.java:31)
    at com.google.apphosting.runtime.jetty.DatastoreSessionStore.createEntityForSession(DatastoreSessionStore.java:72)
    at com.google.apphosting.runtime.jetty.DatastoreSessionStore.saveSession(DatastoreSessionStore.java:94)
    at com.google.apphosting.runtime.jetty.SessionManager$AppEngineSession.save(SessionManager.java:156)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:41)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:57)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    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:480)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
    at com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:484)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.io.NotSerializableException: java.util.logging.Logger
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1197)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1545)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1510)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1433)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1191)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:363)
    at java.util.HashMap.writeObject(HashMap.java:1018)
    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:616)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1497)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1433)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1191)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:363)
    at com.google.apphosting.runtime.SessionManagerUtil.serialize(SessionManagerUtil.java:28)
    ... 32 more

我已经读过in this page这是一个共同的错误,因为Logger不可序列化,所以我在我的项目中声明所有Logger

final static transient Logger = Logger.getLogger(MyClass.class.getName());

但仍然没有解决方案...... 我整天都在努力解决这个问题(事实上,只有部署版本的问题没有帮助......)

我还需要澄清一下,2周前部署的版本运行完美,没有任何问题。今天,相同的版本开始处理错误,如解释。 我想知道原因可能是GAE 1.8.0的新发布版本

感谢您的支持 此致

1 个答案:

答案 0 :(得分:0)

在每个使用Log

的类中使用此“技巧”解决了这个问题
public Logger log()
{
    return Logger.getLogger(this.class.getName());
}

然后在需要日志的类中,我使用了

log().info(...);
log().severe(...);
....

使用此过程,类不存储对象Logger,因此在序列化期间不会尝试序列化Logger对象