2011-01-20 100 views
3

我正在編寫使用LDAP的Spring應用程序。這是我的beans文件。Spring LDA:與contextSource Bean有關的問題

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> 
     <property name="url" value="xxxxx:xxx" /> 
     <property name="base" value="ou=xxxxx,dc=xxxxxxx,dc=xxxxxx" /> 
     <property name="userDn" value="uid=xxxxxxx" /> 
     <property name="password" value="xxxxxxxx" /> 
    </bean> 

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> 
     <constructor-arg ref="contextSource" /> 
    </bean> 

    <bean id="helloLdap" class="a.b.c.HelloLdap"> 
     <property name="ldapTemplate" ref="ldapTemplate" /> 
    </bean> 

</beans> 

這裏是我的豆創建代碼:

ApplicationContext fac = new ClassPathXmlApplicationContext(
       "a/b/c/ldap.xml"); 
HelloLdap hello = (HelloLdap) fac.getBean("helloLdap"); 

這是我的錯誤信息:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource' defined in class path resource [xxxxxxxxxxxx]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'base' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

所以說,(最重要的)

"Property 'base' threw exception". 

我想知道這是否是因爲認證要求StartTLS。我沒有在我的beans文件中的任何地方指出StartTLS身份驗證,所以也許會導致錯誤。不過,我期望認證在豆創建後,而不是在創建期間發生。

有誰知道這是否是原因(StartTLS authenticaton)?如果沒有,我的XML有什麼錯誤的想法嗎?

感謝, KTM

回答

5

答案是錯誤消息:

java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

東西在應用程序需要Apache Commons Lang。下載它,將它添加到你的類路徑中。

+0

哇,這是一個快速反應!我會這樣做,讓你知道它是否有效。 *十字手指* – ktm5124 2011-01-20 19:31:15