【问题标题】:NoClassDefFoundError in Websphere -- JARs are presentWebsphere 中的 NoClassDefFoundError -- 存在 JAR
【发布时间】:2010-12-15 01:54:06
【问题描述】:

我有一个简单的 Spring MVC 应用程序,它从 LDAP 服务器查找一些用户详细信息并使用 JSP 打印出一个简单的 HTML 页面。该应用程序在 Tomcat 6 上运行良好。它使用 Spring LDAP 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,其中包含 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 无法加载的 contextSource 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>

如果有人能指出为什么这不适用于 Websphere,我将非常高兴。我不太确定 Websphere 中的类加载规则,如果对此有任何建议,我将不胜感激。

【问题讨论】:

    标签: java websphere spring-ldap


    【解决方案1】:

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

    NoClassDefFoundError (NCDFE) 确实意味着它无法找到它正在寻找的类。静态初始化中的错误将明确地变成“java.lang.ExceptionInInitializerError”(EIIE) "

    NCDFE 和 EIIE 都是从链接错误扩展而来的。

    一般来说,所有这些错误都可以通过打开服务器的类加载来轻松解决。还可以使用管理控制台中提供的类加载器查看器来帮助您进行故障排除活动。

    HTH 芒露

    【讨论】:

    • 谢谢芒鲁。在启用类加载的情况下浏览日志,我发现正在从另一个位置加载不同版本的 Spring LDAP jar,因为管理员在 JNDI 中存储了 Spring LDAP 上下文源。将我的应用程序的类加载器设置为使用“最后一个父级”解决了这个问题。
    【解决方案2】:

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

    NoClassDefFoundError: 给定的类 可以找到,但是发生了一些事情 初始化时出错(一个 它实现的接口不可能 发现,出了点问题 静态初始化器等)。

    来自here

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 我猜他会得到 ClassNotFound
        猜你喜欢
        • 2013-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多