编程语言
首页 > 编程语言> > java-Spring LDA:contextSource Bean问题

java-Spring LDA:contextSource Bean问题

作者:互联网

我正在编写一个使用LDAP的Spring应用程序.这是我的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>

这是我的bean创建代码:

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.我没有在bean文件中的任何地方指示StartTLS身份验证,所以这可能是导致错误的原因.不过,我希望身份验证会在创建bean之后进行,而不是在创建过程中进行.

有谁知道这是原因(StartTLS身份验证)吗?如果不是,您对我的XML做错了什么有什么想法?

谢谢,
ktm

解决方法:

答案在错误消息中:

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

应用程序中的某些内容需要Apache Commons Lang.将其下载,然后将其添加到您的类路径中.

标签:ldap,spring-ldap,xml,spring,java
来源: https://codeday.me/bug/20191023/1914044.html