原来我之所以需要与众不同的原因
base是因为Spring并未在
base上设置
ContextSource。
当您让Spring
Boot自动配置嵌入式LDAP服务器时,它将在中创建一个
ContextSource这样的目录
EmbeddedLdapAutoConfiguration:
@Bean@DependsOn("directoryServer")@ConditionalOnMissingBeanpublic ContextSource ldapContextSource() { LdapContextSource source = new LdapContextSource(); if (hasCredentials(this.embeddedProperties.getCredential())) { source.setUserDn(this.embeddedProperties.getCredential().getUsername()); source.setPassword(this.embeddedProperties.getCredential().getPassword()); } source.setUrls(this.properties.determineUrls(this.environment)); return source;}如您所见,它在那里没有调用
source.setbase()。因此,为解决此问题,我添加了一个配置文件,
@Profile("embedded")并手动创建了一个ContextSource我
base自己设置的位置(我省略了凭据部分,因为我不对嵌入式服务器使用凭据):
@Configuration@Profile("embedded")@EnableConfigurationProperties({ LdapProperties.class })public class EmbeddedLdapConfig { private final Environment environment; private final LdapProperties properties; public EmbeddedLdapConfig(final Environment environment, final LdapProperties properties) { this.environment = environment; this.properties = properties; } @Bean @DependsOn("directoryServer") public ContextSource ldapContextSource() { final LdapContextSource source = new LdapContextSource(); source.setUrls(this.properties.determineUrls(this.environment)); source.setbase(this.properties.getbase()); return source; }}现在,对于Active
Directory服务器和嵌入式UnboundID服务器,我可以将
base属性值保留在
@Entry相同的位置,并且它可以正常工作。



