开发者

Spring LDA: Problem with contextSource Bean

I am writing a Spring application that uses LDAP. Here is my beans file.

<?xml version="1.0开发者_如何学Python" 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>

Here is my beans creation code:

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

Here is my error message:

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

So it says (most importantly):

"Property 'base' threw exception"

I am wondering whether this is because the authentication requires StartTLS. I don't indicate StartTLS authentication anywhere in my beans file, so perhaps that is causing the error. Still, I would expect the authentication to happen after the beans are created, not during their creation.

Does anyone know if that is the cause (StartTLS authentication)? If not, any idea of what I am doing wrong in my XML?


The answer is in the error message:

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

Something in the application requires Apache Commons Lang. Download that, add it to your classpath.


I was going through same problem and eventually found this

The recommended way of configuring Spring LDAP is to use the custom XML configuration namespace. To make this available, You need to include the Spring LDAP namespace declaration in your bean file

Note these two lines below: xmlns:ldap="http://www.springframework.org/schema/ldap" and 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">

Then you can declare 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜