From 8e9a873787aeb4a87c758c892b22a8f842d4f996 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 11 May 2018 17:48:29 +0200 Subject: [PATCH] Polish "Improve LDAP auto-configuration conditions" Closes gh-13143 --- .../boot/autoconfigure/ldap/LdapAutoConfigurationTests.java | 3 ++- .../src/main/asciidoc/spring-boot-features.adoc | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java index 2908d817a0..9e54fd144a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java @@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.support.LdapContextSource; @@ -120,7 +121,6 @@ public class LdapAutoConfigurationTests { "urls"); assertThat(urls).containsExactly("ldap://localhost:389"); assertThat(contextSource.isAnonymousReadOnly()).isFalse(); - context.getBean(PooledContextSource.class); }); } @@ -128,6 +128,7 @@ public class LdapAutoConfigurationTests { static class PooledContextSourceConfig { @Bean + @Primary public PooledContextSource pooledContextSource( LdapContextSource ldapContextSource) { PooledContextSource pooledContextSource = new PooledContextSource( diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index c464502ca2..7568434c1b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -4539,6 +4539,11 @@ URLs of your server in your application.properties, as shown in the following ex If you need to customize connection settings, you can use the `spring.ldap.base` and `spring.ldap.base-environment` properties. +A `LdapContextSource` is auto-configured based on these settings. If you need to customize +it, for instance to use a `PooledContextSource`, you can still inject the auto-configured +`LdapContextSource`. Make sure to flag your customized `ContextSource` as `@Primary` so +that the auto-configured `LdapTemplate` uses it. + [[boot-features-ldap-spring-data-repositories]]