`

Spring LDAP

阅读更多

遇到一个怪怪的问题:

org.springframework.ldap.CommunicationException: connection closed; nested exception is javax.naming.CommunicationException: connection closed [Root exception is java.io.IOException: connection closed]; remaining name 'cn=001'

 

到javaeye上搜了下,找不到类似问题,只是说CommunicationException是协议错误。

看到很多关于这方面的异常都是出现在证书错误方面,没有出现IOException。

当出现该异常之后,后面的连接居然都连不上了。

 

修改了一下Spring LDAP配置,去掉了pool可以了。记录下此问题,以后再慢慢补充。

	<!-- spring ldap source配置 -->
	<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
		<property name="url" value="ldap://192.168.0.1:389/" />
		<property name="base" value="cn=test,DC=SCTEL,DC=COM,DC=CN" />
		<!--<property name="referral" value="follow"></property>-->
		<property name="userDn" value="cn=root" />
		<property name="password" value="123456" />
	</bean>
	<!--<bean id="poolingContextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
		<property name="contextSource" ref="contextSource" />
		<property name="maxActive" value="20" />
		<property name="maxTotal" value="40" />
		<property name="maxIdle" value="10" />
		<property name="minIdle" value="5" />
		<property name="maxWait" value="5" />
	</bean>-->
	<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
		<constructor-arg ref="contextSource" />
		<!--<property name="contextSource" ref="poolingContextSource" />-->
	</bean>
	<bean id="springLdapDao" class="com.zzt.ldap.SpringLdapDao">
		<property name="ldapTemplate" ref="ldapTemplate" />
	</bean>
	<bean id="ldapManager" class="com.zzt.ldap.LdapManager">
		<property name="springLdapDao" ref="springLdapDao" />
	</bean>

 

 

-----------------------------------------------------------------------------------------------------------------

补充:找出问题原因了,如下

当LDAP服务器重新启动之后,客户端无法重连导致上面问题的产生,配置修改如下就可以了

还是使用 poolingContextSource 这个bean,在该bean中添加

<property name="dirContextValidator" ref="dirContextValidator" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />

 

引用的bean为:

<bean id="dirContextValidator"  class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />

 

附件给出了SpringLDAP测试代码。

包含的jar文件:

commons-lang.jar

commons-logging.jar

commons-pool-1.3.jar

spring.jar

spring-ldap-1.3.0.RELEASE-all.jar

分享到:
评论
2 楼 Z_408 2014-01-02  
谢谢,找好多例子终于成功一个了
1 楼 Java-feifeiok 2011-09-28  
多谢 找了半天终于给解决了 再次感谢

相关推荐

Global site tag (gtag.js) - Google Analytics