ClassCastException 因为在不同的模块中

问题描述 投票:0回答:1

我在使用 spring LDAP 时遇到了这个问题:

类 javax.naming.ldap.LdapName 无法转换为类 java.lang.String (javax.naming.ldap.LdapName 位于加载程序“bootstrap”的模块 java.naming 中;java.lang.String 位于模块 java.base 中加载器“bootstrap”)

这是出现问题的代码片段

private void createUser(LdapAttributes ldapAttributes) {
        LdapName dn = LdapNameBuilder
                .newInstance()
                .add("ou", "users")
                .add("cn", ldapAttributes.getName())
                .build();

        DirContextAdapter context = new DirContextAdapter(dn);

        context.setAttributeValues(
                "objectclass",
                new String[]
                        { "top",
                          "person",
                          "organizationalPerson",
                          "inetOrgPerson" });
        context.setAttributeValue("cn", ldapAttributes.getName());
        context.setAttributeValue("sn", ldapAttributes.getName());
        context.setAttributeValue("userPassword", ldapAttributes.get("userPassword"));

        ldapTemplate.bind(context);
    }

我在 2.4.1 版本中使用 spring org.springframework.ldap:spring-ldap-core 和 org.springframework.ldap:spring-ldap-ldif-core

Springboot 版本为 2.7.12

spring spring-boot ldap spring-ldap
1个回答
0
投票

你尝试过吗

ldapAttributes.getName().toString()

© www.soinside.com 2019 - 2024. All rights reserved.