Java Websphere中的NoClassDefFoundError--存在JAR

Java Websphere中的NoClassDefFoundError--存在JAR,java,websphere,spring-ldap,Java,Websphere,Spring Ldap,我有一个简单的SpringMVC应用程序,它从LDAP服务器中查找一些用户详细信息,并使用JSP打印出一个简单的HTML页面。该应用程序在Tomcat6上运行良好。它使用SpringLDAP 1.3.1和LDAPTemplate进行LDAP查找 但是,当我将此应用程序WAR部署到Websphere 7时,应用程序不会运行——Websphere返回一个500内部服务器错误。查看Websphere的日志文件,我发现 [14/12/10 14:50:09:169 GMT] 00000022 Dispa

我有一个简单的SpringMVC应用程序,它从LDAP服务器中查找一些用户详细信息,并使用JSP打印出一个简单的HTML页面。该应用程序在Tomcat6上运行良好。它使用SpringLDAP 1.3.1和LDAPTemplate进行LDAP查找

但是,当我将此应用程序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)
我的web inf\lib目录包含所有JAR文件,包括
org.springframework.beans-3.0.5.RELEASE.JAR
,其中包含
初始化bean
。因此,我不确定Websphere为什么报告该类丢失

我的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
下面是Websphere在加载时遇到问题的
contextSource
bean的定义(用户名/密码有效,可与Tomcat一起使用):



如果有人能指出这在Websphere上不起作用的原因,我将非常高兴。我对Websphere中的类加载规则不太确定,希望您能给我一些建议。

这是一个棘手且常见的异常。请记住,
NoClassDefFoundError
并不意味着找不到该类,而是意味着:

NoClassDefFoundError:给定的类 可以找到,但有东西不见了 初始化它时出错(错误) 无法实现它所实现的接口 发现某个地方出了问题 静态初始化器等)


从。

请检查您在任何其他可能的jar中是否没有相同的类

打开类加载跟踪。这将告诉您加载了哪些类以及从哪个Jar加载。正如Sajan提到的,类路径中可能存在重复的JAR,并且您期望的类加载器没有加载这个类(并且父类加载器可能加载了一个类)

NoClassDefFoundError(NCDFE)并不意味着它无法找到它正在查找的类。静态初始化中的错误将明确显示为“java.lang.ExceptionInInitializerError”(EIIE) "

NCDFE和EIIE都是从连杆机构误差扩展而来的

通常,通过打开服务器的类加载,可以很容易地排除所有这些错误。还可以使用管理控制台中的类加载程序查看器来帮助您进行故障排除活动


Manglu

请检查您是否在pom.xml文件中添加了依赖项。

谢谢Manglu。在启用类加载的情况下浏览日志,我发现正在从另一个位置加载不同版本的Spring LDAP jar,因为管理员在JNDI中存储了Spring LDAP上下文源我的应用程序使用“ParentLast”修复了这个问题。我想他会被发现的
<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>