Spring LDA:contextSource Bean 的问题
我正在编写一个使用 LDAP 的 Spring 应用程序。这是我的 beans 文件。
<?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中出现异常:创建在类路径资源[xxxxxxxxxxxx]中定义的名称为“contextSource”的bean时出错:设置属性值时出错;嵌套异常是org.springframework.beans.PropertyBatchUpdateException;嵌套的 PropertyAccessExceptions (1) 是: PropertyAccessException 1:org.springframework.beans.MethodInitationException:属性“base”抛出异常;嵌套异常是 java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
所以它说(最重要的是):
"Property 'base' threw exception"
我想知道这是否是因为身份验证需要 StartTLS。我没有在 bean 文件中的任何位置指示 StartTLS 身份验证,因此这可能会导致错误。不过,我希望身份验证发生在 bean 创建之后,而不是在创建期间。
有谁知道这是否是原因(StartTLS 身份验证)?如果没有,知道我在 XML 中做错了什么吗?
I am writing a Spring application that uses LDAP. Here is my beans file.
<?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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案在错误消息中:
应用程序中的某些内容需要 Apache Commons Lang。下载它,将其添加到您的类路径中。
The answer is in the error message:
Something in the application requires Apache Commons Lang. Download that, add it to your classpath.
我遇到了同样的问题,最终发现 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"
然后你可以声明 contextSource:
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"
andhttp://www.springframework.org/schema/ldap https://www.springframework.org/schema/ldap/spring-ldap.xsd"
Then you can declare contextSource: