java - LdapTemplate 搜索捕获并行流和 LdapTemplate 异常

标签 java spring-boot spring-ldap pooling

我在尝试使用 spring-ldap 并行搜索在 LDAP 上搜索组时遇到问题。

我正在进行批处理以将数据从 SQL 数据库加载到 LDAP。我使用 spring-boot 和 spring-ldap。

我的算法尝试使用 ldap 的 gidNumber 在 ldap 中搜索组。在没有并行性(stream.parallelStream)的情况下运行时它工作正常。但是当我使用并行流迭代列表时,我有时会捕获此异常:

java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)

我已将对象从 ContextMapper#mapFromContext 转换为 DirContextAdapter。 Spring-ldap 引用说,如果我不更改 DirObjectFactory LdapContextSource,此方法应该返回 DirContextAdapter 的实例。

我的代码类似于:

ldapTemplate.search(
query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
            (ContextMapper<GroupLdap>) ctx -> {
                DirContextAdapter context = (DirContextAdapter) ctx;
                return new GroupLdap(context, true);
            })

我的应用程序是一个批处理,用于将数据从 SQL 数据库加载到 LDAP。我使用 spring-boot 和 spring-ldap。

我正在使用 spring-boot 2.1.4、OpenLdap 和 ORACLE to SQL-DB。以及 open-jdk-zulu 11。

我的算法尝试使用 ldap 的 gidNumber 在 ldap 中搜索组。在没有并行性(stream.parallelStream)的情况下运行时它工作正常。但是当我使用parallelStream()迭代列表时,有时会捕获ClassCastException:

我放置了 LDAP 池连接,但它不起作用。

我的代码类似于:

    ldapTemplate.search(
    query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
                (ContextMapper<GroupLdap>) ctx -> {
                    DirContextAdapter context = (DirContextAdapter) ctx;
                    return new GroupLdap(context, true);
                })

groupName 是引用“ou=groups,dc=fff,dc=br”的名称;

gid 是一个带有搜索组 gitNumber 的数字。

GroupLdap 是 LDAP 上组的内部表示。

通过并行性,我有时会收到异常:

java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)

我已将对象从 ContextMapper#mapFromContext 转换为 DirContextAdapter。 Spring-ldap 引用说,如果我不更改 DirObjectFactory LdapContextSource,此方法应该返回 DirContextAdapter 的实例。

最佳答案

我们与团队确认,从parallelStream()更改为stream()可以解决ClassCastException的问题。这肯定是 openJdk 的一些缺陷。找不到任何相关内容:https://bugs.openjdk.java.net 。一旦我重现了孤立的问题,我就会报告它。目前,parallelStream 并不总是有效(在少数设置中它可以工作,但在少数情况下则不能)

我使用并且可以使用parallelStream:

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T09:58:13+02:00) Maven home: C:\Program Files\apache-maven-3.5.2\bin.. Java version: 11.0.5, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk-11.0.5 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Colleague has, and experiencing issue: Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:29+02:00) Maven home: C:\tools\ideaIU-2019.2.3.win\plugins\maven\lib\maven3 Java version: 13.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-13.0.2 Default locale: en_US, platform encoding: UTF-8 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

关于java - LdapTemplate 搜索捕获并行流和 LdapTemplate 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56083300/

相关文章:

java - Spring Security 跨源

java - NoSuchBeanDefinitionException : No qualifying bean of type 'java.util.List<org.springframework.shell.ParameterResolver>'

java - Spring Security Active Directory 忽略 PartialResultException

java - 为什么我的图标在 JFrame 中没有改变?

java - Springboot解密JNDI tomcat密码

java - JEdi​​torpane 无法加载 URL

java - 如何在 Java 中将 SID 转换为字符串,反之亦然?

spring-ldap NameNotFoundException 没有这样的对象

java - 单击 "View All"按钮后如何显示 RecyclerView 项目

java - 如何使用当前日期作为函数输入获取月份名称