无法在 ldif 文件的帮助下将示例数据加载到 ldap 服务器中



我需要将批量数据插入LDAP服务器,为此我使用了LdapTestUtils类,但出现一些错误

Gradle 依赖项

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testCompile group: 'org.springframework.ldap', name: 'spring-ldap-test', version: '2.3.2.RELEASE'
}

爪哇代码

public static void loadData() throws Exception
    {
        // Bind to the directory
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl("ldap://127.0.0.1:10389");
        contextSource.setUserDn("uid=admin,ou=system");
        contextSource.setPassword("secret");
        contextSource.setPooled(false);
        contextSource.afterPropertiesSet();
        // Create the Sprint LDAP template
        LdapTemplate template = new LdapTemplate(contextSource);
        // Clear out any old data - and load the test data
        LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com"));
        LdapTestUtils.loadLdif(contextSource, new ClassPathResource("schema.ldif"));
    }

链接 - https://www.programcreek.com/java-api-examples/index.php?api=org.springframework.ldap.test.LdapTestUtils第一个例子

错误 - org.apcahe.directory.server.core 无法解析,它是从 require.class 文件中间接引用的

我缺少什么依赖项?还有其他方法可以做到这一点吗?

public static void loadData() throws Exception
    {
        // Bind to the directory
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl("ldap://127.0.0.1:10389");
        contextSource.setUserDn("uid=admin,ou=system");
        contextSource.setPassword("secret");
        contextSource.setPooled(false);
        contextSource.afterPropertiesSet();
        // Create the Sprint LDAP template
        LdapTemplate template = new LdapTemplate(contextSource);
        // Clear out any old data - and load the test data
     LdapTestUtils.cleanAndSetup(
                contextSource,
                LdapUtils.newLdapName("dn to remove"),
                new ClassPathResource("schema.ldif"));
          }

cleanAndSetup方法对我有用,但它也会重新启动服务器

最新更新