java 中使用ldaptive_Spring LDAP – 在独立的java程序中创建LdapTemplate – 使用Spring LDAP作为CDI资源...

我正在尝试构造一个使用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?

解决方法:

LdapContextSource是InitializingBean所以你需要调用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,spring-ldap

来源: https://codeday.me/bug/20190612/1226023.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值