java Websphere 中的 NoClassDefFoundError -- 存在 JAR
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4446050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoClassDefFoundError in Websphere -- JARs are present
提问by sigint
I have a simple Spring MVC application that looks up some user details from an LDAP server and prints out a simple HTML page using a JSP. The application works fine on Tomcat 6. It uses Spring LDAP 1.3.1 and LDAPTemplate to do the LDAP lookups.
我有一个简单的 Spring MVC 应用程序,它从 LDAP 服务器查找一些用户详细信息,并使用 JSP 打印出一个简单的 HTML 页面。该应用程序在 Tomcat 6 上运行良好。它使用 Spring LDAP 1.3.1 和 LDAPTemplate 进行 LDAP 查找。
However, when I deploy this application WAR to Websphere 7, the app doesn't run -- Websphere returns a 500 Internal server error. Looking at Websphere's log file, I see
但是,当我将此应用程序 WAR 部署到 Websphere 7 时,该应用程序不会运行——Websphere 返回 500 内部服务器错误。查看 Websphere 的日志文件,我看到
[14/12/10 14:50:09:169 GMT] 00000022 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.ldap.core.support.LdapContextSource] for bean with name 'contextSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.beans.factory.InitializingBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
My web-inf\lib directory has all the JAR files, including org.springframework.beans-3.0.5.RELEASE.jar
, which contains InitializingBean
. I'm therefore not sure why Websphere is reporting the class as missing.
我的WEB-INF \ lib目录下有所有的JAR文件,包括org.springframework.beans-3.0.5.RELEASE.jar
,包含InitializingBean
。因此,我不确定为什么 Websphere 报告该课程缺失。
Contents of my web-inf\lib:
我的 web-inf\lib 的内容:
aopalliance.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool-1.5.4.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
ldapbp-1.0.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
spring-ldap-1.3.1.RELEASE-all.jar
And here's the definition of the contextSource
bean which Websphere is having trouble loading (the username/password is valid and works with Tomcat):
以下contextSource
是 Websphere 加载时遇到问题的bean的定义(用户名/密码有效并且可与 Tomcat 一起使用):
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldaps://moo.example.com:1300/" />
<property name="userDn" value="CN=foo,OU=baz,DC=bar,DC=blat,DC=org" />
<property name="password" value="*******" />
</bean>
I'd be very glad if someone could point out why this isn't working on Websphere. I'm not too sure about class-loading rules in Websphere and would appreciate any advice on this.
如果有人能指出为什么这不适用于 Websphere,我会很高兴。我对 Websphere 中的类加载规则不太确定,如果您对此有任何建议,我将不胜感激。
回答by javamonkey79
This is a sticky and common exception. Remember, that NoClassDefFoundError
doesn't mean the class was not found, rather it means:
这是一个棘手且常见的异常。请记住,这NoClassDefFoundError
并不意味着找不到该类,而是意味着:
NoClassDefFoundError: The given class could be found, but something went wrong when initializing it (an interface it implemented could not be found, something went wrong in a static initializer etc.).
NoClassDefFoundError:可以找到给定的类,但在初始化它时出现问题(找不到它实现的接口,静态初始化程序中出现问题等)。
From here.
从这里开始。
回答by Manglu
Turn on Class Loading trace. This would tell you what classes are loaded and from which Jar. As Sajan mentioned chances are that there are duplicate jars in the classpath and the classloader that you expect has not loaded this class (and a parent class loader has likely loaded a class).
打开类加载跟踪。这将告诉您加载了哪些类以及从哪个 Jar 加载。正如 Sajan 提到的,类路径中可能存在重复的 jar,并且您期望的类加载器没有加载这个类(并且父类加载器可能已经加载了一个类)。
NoClassDefFoundError (NCDFE) does mean it could not locate the class that it is looking for. Errors in static initialization would explicitly turn out as a "java.lang.ExceptionInInitializerError" (EIIE) "
NoClassDefFoundError (NCDFE) 确实意味着它无法找到它正在寻找的类。静态初始化中的错误将明确显示为“java.lang.ExceptionInInitializerError”(EIIE)“
Both NCDFE and EIIE extend from Linkage error.
NCDFE 和 EIIE 都源自链接错误。
In general all these errors can easily be troubleshooted by turning on the class loading for the Server. Also use the Class Loader Viewer available in the admin console to aid in your troubleshooting activities.
一般来说,所有这些错误都可以通过打开服务器的类加载轻松解决。还可以使用管理控制台中提供的类加载器查看器来帮助您进行故障排除活动。
HTH Manglu
HTH芒陆
回答by pppppp
Please check if you have added the dependencies in pom.xml file.
请检查您是否在 pom.xml 文件中添加了依赖项。
回答by Sajan Raj
Please check that you don't have the same class in any other possible jar
请检查您是否在任何其他可能的 jar 中没有相同的类