Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringLDAP:由对等方重置连接_Java_Spring_Ldap - Fatal编程技术网

Java SpringLDAP:由对等方重置连接

Java SpringLDAP:由对等方重置连接,java,spring,ldap,Java,Spring,Ldap,我正在使用SpringLDAPTemplate类访问ldap。我使用ldap连接池(PoolgContextSource类)来避免在运行时一直创建连接。但是,我有时会在我的应用程序中遇到此异常: javax.servlet.ServletException: org.springframework.ldap.CommunicationException: Connection reset; nested exception is javax.naming.CommunicationExcept

我正在使用SpringLDAPTemplate类访问ldap。我使用ldap连接池(PoolgContextSource类)来避免在运行时一直创建连接。但是,我有时会在我的应用程序中遇到此异常:

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>
不久之后,我得到了一个例外:

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)

提前感谢。

看起来超时定义太低了。Oracle有一个官方网站可以让您找出问题的根源,很可能不是“Spring”,而是Sun Ldap连接器或您的Ldap服务器。很多人都反对提供链接,但我就是不能复制这个页面,也许你可以试试他们网站上的“原始”声明,看看它是否也发生了。这将使您离解决方案更近一步。(可能是ldap超时配置)


1) 我正在使用SpringLDAP,它是Java(JNDI)LDAP的包装器。我不知道如何使用Spring库设置这个超时。2) 我在问题中的异常之前添加了一个警告,该问题似乎是一个无效操作,而不是超时。您试图执行什么操作?我只是设置了Sprint LDAP属性,在使用它之前测试它从LDAP连接池获得的每个LDAP连接是否有效。可能Spring会向LDAP服务器发送一个简单的虚拟请求来验证连接,但我不知道该请求执行的是哪个LDAP操作。我必须阅读框架代码才能找到答案。您是否确保您拥有ldap的相应权限?剩余名称为“”,是否搜索空字符串?如果是这样,你能试着添加几个字符吗?不相关。此属性没有默认值,因此没有默认的读取超时,如果存在读取超时,则不会导致连接重置,它将导致
SocketTimeoutException
,该异常将被包装在某些LDAP异常中。注意:一秒钟的读取超时是一个数量级太短。它应该是10秒到1分钟。
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)
env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put("com.sun.jndi.ldap.read.timeout", "1000");
env.put(Context.PROVIDER_URL, "ldap://localhost:2001");

Server s = new Server();

try {

    // start the server
    s.start();

   // Create initial context
   DirContext ctx = new InitialDirContext(env);
   System.out.println("LDAP Client: Connected to the Server");
        :
        :
} catch (NamingException e) {
   e.printStackTrace();
}