Spring 引导 LDAP - 池 属性 用于自动配置

Spring Boot LDAP - pooled property for auto configuration

在 Spring 引导中,我可以传递将被选择用于自动配置的属性:

是否有任何 spring.ldap.* 属性 设置 pooled=true 以避免使用显式 LdapTemplate 配置?

LdapContextSource contextSource = new LdapContextSource();
contextSource.setPooled(true);

根据 the Appendix that lists all of the Spring Boot properties, no. I also looked at the LdapProperties class 的说法,它在运行时存储这些值,但没有看到任何有助于池化的内容。我怀疑您必须继续手动执行此操作。

也许向他们提交 PR?如果社区有需要,他们似乎愿意添加东西。

您可以使用 JVM 参数设置 ldap 池属性。您在启动应用程序时指定它们。

例如:

-Dcom.sun.jndi.ldap.connect.pool.maxsize=10 
-Dcom.sun.jndi.ldap.connect.pool.prefsize=5 
-Dcom.sun.jndi.ldap.connect.pool.timeout=300000

我读到的所有内容都建议使用 PoolingContextSource 完成配置。 LDAP 身份验证过程需要一个有问题的两阶段过程。以下内容来自 Spring LDAP 大师 Mattias Hellborg Arthursson 的博客。

Built-in JNDI Connection Pooling

The pooled property of ContextSource has previously defaulted to true, enabling the built-in Java LDAP connection pooling by default. However the built-in LDAP connection pooling suffers from several deficiencies (most notable there is no way of doing connection validation and configuration is cumbersome), which is why we decided to change the default to false . If you require connection pooling we strongly recommend using the Spring LDAP PoolingContextSource instead.

https://blog.jayway.com/2008/10/27/whats-new-in-spring-ldap-13/

https://docs.spring.io/spring-ldap/docs/1.3.2.RELEASE/reference/html/pooling.html