【问题标题】:Error with Spring ldap poolingSpring ldap池错误
【发布时间】:2021-01-11 13:23:18
【问题描述】:

我构建了 async jersey web 服务,现在我需要使用 ldap 进行一些操作。 我已经在这种模式下配置了 Spring beam.xml:

<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="${ldap.url}" />
        <property name="base" value="${ldap.base}" />
        <property name="userDn" value="${ldap.userDn}" />
        <property name="password" value="${ldap.password}" />
        <property name="pooled" value="false" />
    </bean>

    <bean id="contextSource"
        class="org.springframework.ldap.pool.factory.PoolingContextSource">
        <property name="contextSource" ref="contextSourceTarget" />
    </bean>

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

    <bean id="ldapTreeBuilder" class="com.me.ldap.LdapTreeBuilder">
        <constructor-arg ref="ldapTemplate" />
    </bean>


    <bean id="personDao" class="com.me.ldap.PersonDaoImpl">
        <property name="ldapTemplate" ref="ldapTemplate" />
    </bean>

但是当我尝试使用 ldap 时出现此错误:

Error creating bean with name 'contextSource' defined in class path resource [config/Beans.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedPoolableObjectFactory

在我的项目中,我有 commons-pool2-2.2.jar lib,但我仍然有这个错误..我尝试在 TOMCAT_PATH/lib 中添加 commons-pool2-2.2.jar 但不起作用..

更新:

如果我把 commons-pool-1.6.jar 它工作.. 但如果我想使用 pool2 我该怎么办?只有我必须更改类客栈commons-pool2-2.2.jar?

【问题讨论】:

    标签: spring-data spring-ldap


    【解决方案1】:

    更新答案:

    至少从 Spring LDAP 2.3.2 开始,您现在可以使用 commons-pool2。 Spring LDAP 现在提供了两个类:

    对于 commons-pool 1.x: org.springframework.ldap.pool.factory.PoolingContextSource

    对于 commons-pool 2.x: org.springframework.ldap.pool2.factory.PooledContextSource

    详细信息可以在这里找到: https://github.com/spring-projects/spring-ldap/issues/351#issuecomment-586551591

    原答案:

    不幸的是 Spring-Ldap 使用 commons-pool 而不是 commons-pool2。正如您发现的那样 org.apache.commons.pool.KeyedPoolableObjectFactory 类在 commons-pool2 中不存在(它具有不同的包结构),因此出现错误。

    Spring-ldap 项目存在 Jira 问题,要求他们升级/支持 commons-pool2: https://jira.spring.io/browse/LDAP-316

    在完成之前,您必须使用 commons-pool 1.6。

    【讨论】:

    • 现在支持commons-pool2
    • 我正在使用 Spring Boot 2.4.1 和 spring-security-ldap 并且仍然需要 commons-pool v1.6。
    • @Avec,spring-ldap Jira Issue 中的这条评论详细说明了使用 commons-pool2 需要做什么:github.com/spring-projects/spring-ldap/issues/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    相关资源
    最近更新 更多