gpt4 book ai didi

spring - 无法让 PropertyPlaceholderConfigurer 工作

转载 作者:行者123 更新时间:2023-12-04 17:21:58 25 4
gpt4 key购买 nike

我正在使用 LDAP 对 Web 应用程序中的用户进行身份验证。 LDAP 相关 bean 在名为 spring-servlet-security-ldap.xml 的单独文件中配置(现在称为 ldap.xml)。我的主 Web 应用程序上下文文件“spring-servlet.xml”导入 spring-servlet-security.xml,它再次导入 ldap 文件。如果我不使用属性文件,则此设置有效。

我已经包含了层次结构详细信息,因为类似的问题网站 PropertyPlaceholderConfigurer 被覆盖作为原因。

LDAP 设置的属性文件位于 WEB-INF 目录中。

我在 ldap.xml 中定义了 PropertyPlaceholderConfigurer,如下所示

<bean id="placeHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>WEB-INF/ldap.properties</value></property>
</bean>

我正在引用同一文件中的属性

<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource" depends-on="placeHolderConfigurer">
<constructor-arg value="ldap://xx.xx.xx.xx:389/dc=example,dc=com" />
<property name="userDn"><value>{ldap.userDN}</value></property>
<property name="password" value="secret" />
</bean>

日志表明该属性正在加载。

INFO Thread-0 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/ldap.properties]

但是该值并未引用属性文件,并且正在使用字面上配置的值。我已从数据包跟踪中验证绑定(bind)请求针对 DN {ldap.userDN}

最佳答案

我认为您只需要一个 $ 符号作为占位符:${ldap.userDN}

这是 PropertyPlaceholderConfigurer 默认情况下期望的占位符格式。这是通过 placeholderPrefixplaceholderSuffix 属性控制的;默认情况下,分别为 ${}

关于spring - 无法让 PropertyPlaceholderConfigurer 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com