栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring注解@ Entry.base不支持SpEL

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring注解@ Entry.base不支持SpEL

原来我之所以需要与众不同的原因

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
相同的位置,并且它可以正常工作。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号