我正在使用 cglib 来增强 HashMap,因此我可以拦截 HashMap 上的方法调用。
它在我的本地计算机上运行良好,当我在 Eclipse 中作为谷歌网络应用程序运行时。但是,一旦部署在服务器上,我就会收到异常“java.lang.NoClassDefFoundError: [Ljava/util/HashMap$Entry;”
引发异常的代码行是:
Enhancer.create(HashMap.class, new SomeInterceptor());
我正在使用最新的 Eclipse 插件(3.7)。我正在使用 cglib 2.2 版(cglib-nodep-2.2.jar)
编辑:这很有趣:如果我创建一个从 HashMap 扩展的类,那么我可以毫无问题地增强该类。例如,以下代码有效:
public class MyHashMap extends HashMap {
}
Enhancer.create(MyHashMap.class, new SomeInterceptor());
Enhancer 适用于 TreeMap、HashSet 和 TreeSet:ENDEDIT
堆栈跟踪是:
java.lang.NoClassDefFoundError: [Ljava/util/HashMap$Entry;
at com.google.appengine.runtime.Request.process-02796318ce7d3a7b(Request.java)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2444)
at java.lang.Class.getDeclaredMethod(Class.java:229)
at net.sf.cglib.proxy.Enhancer.getCallbacksSetter(Enhancer.java:630)
at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:618)
at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:612)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:634)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:663)
at com.enhancetest.EnhanceTestServlet.doGet(EnhanceTestServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
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 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 org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
at java.lang.Thread.run(Thread.java:679)
原因:java.lang.ClassNotFoundException: java.util.HashMap$Entry ... 35 更多