我正在使用 Spring LdapTemplate 类来访问 ldap。我正在使用一个 ldap 连接池(PoolingContextSource 类)来避免在运行时一直创建连接。但是,有时在我的应用程序中会遇到此异常:
javax.servlet.ServletException: org.springframework.ldap.CommunicationException: Connection reset;
nested exception is javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset];
Remaining name: 'ou=memberlist,ou=mygroups,o=mycompany.com'
(...)
我的 ldap 类在以下 xml 中定义
<bean id="contextSource" class="com.ibm.tp4.spring.ldap.CustomPoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
<property name="testWhileIdle" value="true" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="dirContextValidator">
<bean class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
</property>
</bean>
<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="${ldap.url}" />
<property name="pooled" value="false" />
<property name="anonymousReadOnly" value="true" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="myLdapResolver" class="com.ibm.tp4.model.service.user.MyLdapResolver">
<constructor-arg ref="ldapTemplate" />
<property name="ldapUserSearchBase" value="${ldap.user.search_base}" />
<property name="ldapUserEmailAddressField" value="${ldap.user.email_address}" />
<property name="ldapAttributes" value="${ldap.user.attributes}" />
</bean>
有没有人遇到过这个问题并可以提出解决方案?
我考虑过在池属性中使用 testOnReturn 参数,而不是现在使用的连接驱逐器。当我这样做时,当我在浏览器中运行我的 Web 应用程序时收到以下警告:
WARN [org.springframework.ldap.pool.validation.DefaultDirContextValidator] -
DirContext 'javax.naming.ldap.InitialLdapContext@d150d15' failed validation with an
exception.javax.naming.OperationNotSupportedException: [LDAP: error code 53 - Unwilling To Perform];
Remaining name: ''
不久之后,我得到了这个例外:
org.springframework.dao.DataAccessResourceFailureException: Failed to borrow DirContext from pool.; nested exception is java.util.NoSuchElementException: Could not create a validated object, cause: ValidateObject failed
org.springframework.ldap.pool.factory.PoolingContextSource.getContext(PoolingContextSource.java:425)
提前致谢。