spring-ldap
spring-ldap copied to clipboard
Pooling with LdapRepository
When using LdapTemplate to explicitly execute LDAP queries, we could configure connection pooling parameters within @Configuration like the following:
@Bean
public LdapTemplate ldapTemplate() throws Exception {
return new LdapTemplate(poolingLdapContextSource());
}
@Bean
public ContextSource poolingLdapContextSource() {
PoolingContextSource poolingContextSource = new PoolingContextSource();
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setMaxActive(maxActive);
poolingContextSource.setMaxTotal(maxTotal);
poolingContextSource.setMaxIdle(maxIdle);
poolingContextSource.setMinIdle(minIdle);
poolingContextSource.setMaxWait(maxWait);
poolingContextSource.setWhenExhaustedAction(new Byte(whenExhaustedAction));
poolingContextSource.setTestOnBorrow(testOnBorrow);
poolingContextSource.setTestWhileIdle(testWhileIdle);
poolingContextSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
poolingContextSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
poolingContextSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
return poolingContextSource;
}
Question: However, when using LdapRepository, which takes care of implementing CRUD operations for me, there is no need for explicit queries using LdapTemplate (at least for simple use-cases). How can I configure the @Repository to use connection pooling? and how can I set pooling parameters?
Now that I investigate further, I think exactly same config should work with LdapRepository as well. The LdapRepository should just use my ldapTemplate bean supplied above instead of the default one(?) Is that understanding correct?