【问题标题】:Spring LDA: Problem with contextSource BeanSpring LDA:contextSource Bean 的问题
【发布时间】:2011-06-12 16:51:47
【问题描述】:

我正在编写一个使用 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");

这是我的错误信息:

线程“main”中的异常 org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为“contextSource”的 bean 时出错 [xxxxxxxxxxxx]:设置属性值时出错;嵌套异常是 org.springframework.beans.PropertyBatchUpdateException;嵌套的 PropertyAccessExceptions (1) 是: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'base' 抛出异常;嵌套异常是 java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

所以它说(最重要的是):

"Property 'base' threw exception"

我想知道这是否是因为身份验证需要 StartTLS。我没有在我的 beans 文件中的任何地方指示 StartTLS 身份验证,所以这可能是导致错误的原因。不过,我希望身份验证发生在 bean 创建之后,而不是在它们创建期间。

有谁知道这是否是原因(StartTLS 身份验证)?如果没有,知道我在 XML 中做错了什么吗?

【问题讨论】:

    标签: java xml spring ldap spring-ldap


    【解决方案1】:

    答案在错误信息中:

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

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

    【讨论】:

    • 哇,反应真快!我会这样做并让你知道它是否有效。 交叉手指
    【解决方案2】:

    我遇到了同样的问题,最终找到了this

    配置 Spring LDAP 的推荐方式是使用自定义 XML 配置命名空间。要使其可用,您需要在 bean 文件中包含 Spring LDAP 命名空间声明

    注意下面这两行:xmlns:ldap="http://www.springframework.org/schema/ldap"http://www.springframework.org/schema/ldap https://www.springframework.org/schema/ldap/spring-ldap.xsd"

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:ldap="http://www.springframework.org/schema/ldap"
           xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/ldap https://www.springframework.org/schema/ldap/spring-ldap.xsd">
    

    然后就可以声明contextSource了:

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

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 2011-08-16
      • 2011-06-22
      • 2016-09-11
      • 1970-01-01
      相关资源
      最近更新 更多