Spring LDAP - 在独立 java 程序中创建 LdapTemplate - 使用 Spring LDAP 作为 CDI 资源

标签 spring ldap spring-ldap

我正在尝试使用 spring 数据构造一个 LdapTemplate 对象。

 public class LDAPTemplate {

        public static void main(String[] args) {
            LdapContextSource lcs = new LdapContextSource();
            lcs.setUrl("ldap://localhost:389/");
            lcs.setUserDn("cn=Manager, dc=example, dc=com");
            lcs.setPassword("secret1");
            lcs.setDirObjectFactory(DefaultDirObjectFactory.class);
            LdapTemplate ldap = new LdapTemplate(lcs);
            ldap.lookup("cn=aaa");

        }

    }

我想知道实例化 ldap 模板对象的正确方法。因为当我执行查找时,它会抛出 NPE。

我正在尝试在 CDI 上下文中使用 LDAP Spring,而不使用 spring。如果你能指点一下那就太好了。 Spring LDAP 是否依赖于 spring?

最佳答案

LdapContextSourceInitializingBean 所以你需要调用 afterPropertiesSet...

和 JavaDoc:

When using implementations of this class outside of a Spring Context it is necessary to call afterPropertiesSet() when all properties are set, in order to finish up initialization.

关于Spring LDAP - 在独立 java 程序中创建 LdapTemplate - 使用 Spring LDAP 作为 CDI 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435932/

相关文章:

java - Spring.mvc.servlet.path 与 Server.servlet.context-path

go - 使用 goLang 的 LDAP 身份验证

java - 需要帮助设置 ActiveDirectoryLdapAuthenticationProvider 的属性

java - 使用 spring、eclipse 和 pluto 调试 JSR 168 Portlet

spring - 如何在 Spring Boot 服务应用程序中的 REST 服务调用之间按原样传递请求参数?

spring - 使用 spring-cloud-vault 访问保管库 secret 并在 application.properties 中使用它

Spring LDAP - 如何管理编码(SHA)密码

c# - 如何使用 Active Directory 从属性中检索值?

java - Spring 启动测试 : @TestPropertySource not overriding @EnableAutoConfiguration

java - Spring LDAP 支持的 LDAP 提供程序列表