2010-12-15 118 views
1

我有一个简单的Spring MVC应用程序,它从LDAP服务器查找一些用户详细信息,并使用JSP打印出一个简单的HTML页面。该应用程序在Tomcat 6上运行良好。它使用Spring LDAP 1.3.1和LDAPTemplate来执行LDAP查找。Websphere中的NoClassDefFoundError - JAR文件存在

但是,当我将此应用程序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,其中包含InitializingBean。因此,我不确定为什么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不太顺利载入(用户名/密码是有效的,并与Tomcat的作品)的contextSource bean的定义:

<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> 

如果有人能指出为什么这不在Websphere上工作,我会很高兴。我不太确定Websphere中的类加载规则,并希望得到有关此方面的任何建议。

回答

3

打开类加载跟踪。这会告诉你什么类被加载,并从哪个罐子。正如Sajan提到的,机会是类路径中存在重复的jar,并且您期望的类加载器没有加载此类(并且父类加载器可能已加载类)。

NoClassDefFoundError(NCDFE)确实意味着它找不到它正在查找的类。在静态初始化错误会明确地变成为“java.lang.ExceptionInInitializerError”(EIIE) “

两个NCDFE和EIIE从链误差扩大。

一般而言,所有这些错误可以很容易地通过旋转来troubleshooted在类加载的服务器。还可以使用类装载器查看器管理控制台提供故障排除活动提供帮助。

HTH Manglu

+0

谢谢Manglu。在启用类加载的情况下浏览日志,我发现从另一个位置加载了不同版本的Spring LDAP jar,因为管理员在JNDI中存储了一个Spring LDAP上下文源。设置我的应用程序的类加载器使用“最后一个父母”解决了这个问题。 – sigint 2010-12-20 12:27:40

3

这是一个粘性和常见的例外。请记住,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.).

here

1

请检查您是否在任何其他可能的罐子中没有相同的班级

1

请检查您是否添加了pom.xml文件的依赖关系。

+0

我想他会得到ClassNotFound – kboom 2014-08-18 12:57:44

相关问题