spring ldap pool 连接池
2015-06-27 21:32
375 查看
遇到一个怪怪的问题:
Java代码
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可以了。记录下此问题,以后再慢慢补充。
Xml代码
<!-- 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中添加
Xml代码
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
引用的bean为:
Xml代码
<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
Java代码
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可以了。记录下此问题,以后再慢慢补充。
Xml代码
<!-- 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中添加
Xml代码
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
引用的bean为:
Xml代码
<bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- spring ldap source配置 --> <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="url" value="ldap://127.0.0.1:389/" /> <property name="base" value="cn=test,DC=SCTEL,DC=COM,DC=CN" /> <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="dirContextValidator" ref="dirContextValidator" /> <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" /> <property name="testOnBorrow" value="true" /> <property name="testWhileIdle" value="true" /> </bean> <bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" /> <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> <property name="contextSource" ref="poolingContextSource" /> </bean> <bean id="springLdapDao" class="com.zzt.application.common.SpringLdapDao"> <property name="ldapTemplate" ref="ldapTemplate" /> </bean> <bean id="LdapManager" class="com.zzt.application.common.LdapManager"> <property name="springLdapDao" ref="springLdapDao" /> </bean> </beans>
附件给出了SpringLDAP测试代码。
包含的jar文件:
commons-lang.jar
commons-logging.jar
commons-pool-1.3.jar
spring.jar
spring-ldap-1.3.0.RELEASE-all.jar
相关文章推荐
- 浅谈Java分布式计算
- java学习之旅31--面向对象_04_程序执行过程的内存分析_01
- Eclipse修改Project的目录位置
- eclipse自动生成hibernate配置文件插件MiddleGenIDE
- LeetCode_59---Spiral Matrix II
- LeetCode_58---Length of Last Word
- Vijava 学习笔记之(VirtualMachine 更改虚拟机系统磁盘大小)
- eclipse中hibernate配置文件自动提示
- Spring过滤器filter拦截服务
- 将IDEA快捷键改为Eclipse模式
- 2015062706 - EffactiveJava笔记 - 第39条 必要时进行保护性拷贝
- 如何停止一个正在运行的java线程?
- 如何快速从Ubuntu系统的eclipse下导出jar包(MapReduce程序)
- DataBase --- Intellij IDEA 14.1.4使用Java连接SQL Server教程
- PhoneGap Eclipse 分别在虚拟机和手机上进行调试
- 【JAVA基础】-标识符与关键字
- Myeclipse8.6中安装SVN插件
- Java学习日记之basic
- myeclipse中的jdk版本问题
- Java中的泛型(1)