Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring批注@Entry.base中不支持SpEL_Java_Spring_Spring Boot_Spring El_Spring Ldap - Fatal编程技术网

Java Spring批注@Entry.base中不支持SpEL

Java Spring批注@Entry.base中不支持SpEL,java,spring,spring-boot,spring-el,spring-ldap,Java,Spring,Spring Boot,Spring El,Spring Ldap,我使用SpringDataLDAP和SpringBoot为嵌入式未绑定服务器提供开箱即用的支持。但是,当我使用Spring Data LDAP的@Entry注释时,我需要根据使用的是嵌入式未绑定LDAP服务器还是远程Active Directory服务器,在注释中指定不同的基 我试图通过指定以下内容对基于SpEL和概要文件的属性执行此操作: @Entry(base = "${ldap.person.base}", ...) 然后我有一个application.propreties和ldap.p

我使用SpringDataLDAP和SpringBoot为嵌入式未绑定服务器提供开箱即用的支持。但是,当我使用Spring Data LDAP的
@Entry
注释时,我需要根据使用的是嵌入式未绑定LDAP服务器还是远程Active Directory服务器,在注释中指定不同的

我试图通过指定以下内容对基于SpEL和概要文件的属性执行此操作:

@Entry(base = "${ldap.person.base}", ...)
然后我有一个
application.propreties
ldap.person.base=OU=AD person base
以及一个
application embedded.properties
ldap.person.base=OU=embedded person base

但是,
@Entry
注释似乎不支持SpEL评估:

javax.naming.InvalidNameException:无效名称:${ldap.person.base}


Spring LDAP中有一个用于添加对该功能的支持,但是在Spring LDAP中支持它之前,我是否有任何解决方法或其他方法可以实现这一点?

我不确定我是否遵循了这一点,但假设您在Spring Boot中使用LDAP自动配置,根据您使用的配置文件将属性
spring.ldap.base
设置为一个或另一个(
OU=AD Person base
OU=Embedded Person base
)还不够吗

EmbeddedLdapAutoConfiguration
LdapAutoConfiguration
都使用
LdapProperties
对象在bean创建期间设置
LdapContextSource
上的各种属性,包括其
。据我所知,如果设置了
LdapContextSource.base
,则不必为代码库中的每个
@条目定义它


如果你没有使用自动配置,如果我的假设是正确的,您应该仍然能够创建自己的
LdapContextSource
bean,并根据Spring属性将其
base
设置为所需的值。

结果表明,我需要不同的
base
首先是因为Spring没有在
ContextSource
上设置
base

当您让Spring Boot自动配置嵌入式LDAP服务器时,它会在
EmbeddedLdapAutoConfiguration
中创建一个
ContextSource

@Bean
@DependsOn("directoryServer")
@ConditionalOnMissingBean
public 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
属性的值对于Active Directory服务器和嵌入的未绑定服务器保持相同,并且可以正常工作。

在@PavanKumarJorrigala谢谢-添加了问题链接中有一个未解决的问题。我最近也发现了这一点。当我这样做时,它在嵌入式版本中工作,但我得到
javax.naming.PartialResultException:Unprocessed Continuation Reference(s);应用程序对Active Directory执行LDAP搜索时剩余的名称“/”
。如果我在我的
Person
条目中指定
base=“OU=Domain Users”
,它会工作,但这会破坏嵌入式版本。很好地让它工作!请考虑一下我的回答,因为你显然用了我建议的方法去解决它。
@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;
    }
}