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

查看:55
本文介绍了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?

推荐答案

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

还有JavaDoc:

在Spring Context之外使用此类的实现时当所有属性都为设置,以完成初始化.

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天全站免登陆