我有一個簡單的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中的類加載規則,並希望得到有關此方面的任何建議。
謝謝Manglu。在啓用類加載的情況下瀏覽日誌,我發現從另一個位置加載了不同版本的Spring LDAP jar,因爲管理員在JNDI中存儲了一個Spring LDAP上下文源。設置我的應用程序的類加載器使用「最後一個父母」解決了這個問題。 – sigint 2010-12-20 12:27:40