Spring LDAP - 在独立 java 程序中创建 LdapTemplate - 使用 Spring LDAP 作为 CDI 资源 [英] Spring LDAP - Creation of LdapTemplate in standalone java program - Using Spring LDAP as CDI Resource

查看:33
本文介绍了Spring LDAP - 在独立 java 程序中创建 LdapTemplate - 使用 Spring LDAP 作为 CDI 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个使用弹簧数据的 LdapTemplate 对象.

I am trying to construct a LdapTemplate object of using spring data.

 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.

I wanted to know is that the right way to instantiate ldap template object. Because when I perform a lookup, it throws NPE.

我试图在 CDI 上下文中使用 LDAP Spring,而根本不使用 spring.如果您对此有指示会很好​​.Spring LDAP是否依赖spring?

I am trying to use LDAP Spring in CDI context without using spring at all. If you have pointers on that would be nice. Does Spring LDAP is dependent on spring?

推荐答案

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

LdapContextSource is InitializingBean so you need to call afterPropertiesSet...

还有 JavaDoc:

And the JavaDoc:

在 Spring 上下文之外使用此类的实现时当所有属性都被调用时,必须调用 afterPropertiesSet()设置,以完成初始化.

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 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆