Ich habe zwei LDAP-Server, die ich in einem Round-Robin-Modus verwenden möchte. Dieser Code scheint immer den ersten Server auszuwählen. Wie kann ich es gleichmäßig wählen?Load Balancing LDAP-Verbindung im Frühjahr
private static LdapTemplate createLdapTemplate(String[] urls, String username, String password) {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrls(urls);
contextSource.setBase(LDAP_SEARCH_BASE);
// username is the same for both LDAP servers
contextSource.setUserDn(username);
contextSource.setPassword(password);
contextSource.setPooled(true);
contextSource.afterPropertiesSet();
return new LdapTemplate(contextSource);
}
und ich verwende die LDAP-Vorlage wie folgt:
SearchControls searchControls = new SearchControls();
searchControls.setTimeLimit(5000);
List ldapResultList = ldapTemplate.search("", filter.encode(), searchControls, (ContextMapper) o -> {
// do things with result...
});