“NoClassDefFoundError:无法初始化类"错误 [英] "NoClassDefFoundError: Could not initialize class" error

查看:37
本文介绍了“NoClassDefFoundError:无法初始化类"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的项目时,我得到了很多关于这个错误的输出:

<上一页>2009 年 9 月 9 日上午 8:22:23 org.apache.catalina.core.StandardWrapperValve 调用严重:servlet Jersey 的 Servlet.service() 抛出异常java.lang.NoClassDefFoundError:无法初始化类 SpringFactory在 com.point2.prospect.persistence.hibernate.HibernateTransactionInterceptor.doFilter(HibernateTransactionInterceptor.java:17)在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)在 com.point2.prospect.restapi.ServerErrorInterceptor.doFilter(ServerErrorInterceptor.java:27)在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)在 java.lang.Thread.run(Thread.java:619)

我注意到这个问题在整个网络上都有被问到的模式,但没有真正的答案.这种错误的一般原因是什么?

解决方案

NoClassDefFound 错误是一个模糊的错误,通常隐藏着更严重的问题.它与 ClassNotFoundException 相同(当类不存在时抛出).

NoClassDefFound 可能表示类不存在,正如 javadocs 所指出的那样,但它通常在类加载器加载类的字节并在它们上调用defineClass"之后抛出.还要仔细检查您的完整堆栈跟踪是否有其他线索或可能的原因"异常(尽管您的特定回溯显示没有).

当您收到 NoClassDefFoundError 时首先要查看的是类的静态位,即在定义类期间发生的任何初始化.如果失败,它将抛出 NoClassDefFoundError - 它应该抛出 ExceptionInInitializerError 并指出问题的详细信息,但根据我的经验,这些很少见.它只会在第一次尝试定义类时执行 ExceptionInInitializerError,之后它只会抛出 NoClassDefFound.所以看看之前的日志吧.

因此,我建议查看 HibernateTransactionInterceptor 行中的代码并了解它需要什么.似乎无法定义类 SpringFactory.因此,也许检查该类中的初始化代码,这可能会有所帮助.如果您可以调试它,请将其停止在上面的最后一行 (17) 并调试到,以便您可以尝试找到导致异常的确切行.还要在日志的更上方检查一下,如果你很幸运,可能会出现 ExceptionInInitializerError.

When I run my project, I get numerous outputs of this error:

Sep 9, 2009 8:22:23 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Jersey threw exception
java.lang.NoClassDefFoundError: Could not initialize class SpringFactory
        at com.point2.prospect.persistence.hibernate.HibernateTransactionInterceptor.doFilter(HibernateTrans
actionInterceptor.java:17)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.point2.prospect.restapi.ServerErrorInterceptor.doFilter(ServerErrorInterceptor.java:27)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)

I notice that this problem has a pattern of being asked all over the web, but with no real answers. What is a general cause for this kind of error?

解决方案

NoClassDefFound error is a nebulous error and is often hiding a more serious issue. It is not the same as ClassNotFoundException (which is thrown when the class is just plain not there).

NoClassDefFound may indicate the class is not there, as the javadocs indicate, but it is typically thrown when, after the classloader has loaded the bytes for the class and calls "defineClass" on them. Also carefully check your full stack trace for other clues or possible "cause" Exceptions (though your particular backtrace shows none).

The first place to look when you get a NoClassDefFoundError is in the static bits of your class i.e. any initialization that takes place during the defining of the class. If this fails it will throw a NoClassDefFoundError - it's supposed to throw an ExceptionInInitializerError and indicate the details of the problem but in my experience, these are rare. It will only do the ExceptionInInitializerError the first time it tries to define the class, after that it will just throw NoClassDefFound. So look at earlier logs.

I would thus suggest looking at the code in that HibernateTransactionInterceptor line and seeing what it is requiring. It seems that it is unable to define the class SpringFactory. So maybe check the initialization code in that class, that might help. If you can debug it, stop it at the last line above (17) and debug into so you can try find the exact line that is causing the exception. Also check higher up in the log, if you very lucky there might be an ExceptionInInitializerError.

这篇关于“NoClassDefFoundError:无法初始化类"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆