我正在尝试使用 spring-ldap org.springframework.ldap.support.LdapContextSource 类访问 LDAP。
以下是我的代码。
配置文件
<bean id="contextSource"
class="org.springframework.ldap.support.LdapContextSource">
<property name="url" value="ldap://url:11539" />
<property name="base" value="o=ctc" />
<property name="userName" value="cn=admin,ou=Users,ou=CFG,o=ctc" />
<property name="password" value="password" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="mail_AdapterImpl"
class="com.MAIL_AdapterImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
<property name="mailAccount" ref="LdapDTO" />
</bean>
实现类
private LdapTemplate mail_ldapTemplate;
private Ldap_DTO mailAccount;
private LdapTemplate ldapTemplate;
// logger used for logging the actions (request/response)
static final Logger usage_log = Logger.getLogger("USAGE");
List l = new ArrayList();
public boolean isPabguidExists(HashMap transferObject) {
if(ldapTemplate != null)
{
mapp_logger.info("Inside ldapTemplate not null");
l = ldapTemplate.search("", "(cn=04543552)",new ABCAttributeMapper());
mapp_logger.info("Size of the List"+l.size());
}
.pom 文件
我在 pom 文件中添加了以下依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-ldap</artifactId>
<version>1.1.2</version>
</dependency>
但我得到以下异常。
Error Logs:
12:42:23,053 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource' defined in ServletContext resource [/WEB-INF/app-beans.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com.sun.jndi.ldap.ctl.ResponseControlFactory from [Module "deployment.MAPP.war:main" from Service Module Loader]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.10.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_31]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_31]
Caused by: java.lang.NoClassDefFoundError: com.sun.jndi.ldap.ctl.ResponseControlFactory from [Module "deployment.ASSPP.war:main" from Service Module Loader]
at org.springframework.ldap.support.LdapContextSource.class$(LdapContextSource.java:42) [spring-ldap-1.1.2.jar:1.1.2]
at org.springframework.ldap.support.LdapContextSource.<clinit>(LdapContextSource.java:42) [spring-ldap-1.1.2.jar:1.1.2]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_31]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.6.0_31]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.6.0_31]
at java.lang.reflect.Constructor.newInstance(Unknown Source) [rt.jar:1.6.0_31]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
... 21 more