spring - 无法让 PropertyPlaceholderConfigurer 工作

标签 spring

我正在使用 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/

相关文章:

java - 我们什么时候使用 SpringApplicationBuilder?

java - Spring批处理-通过提取自动生成的 key 写入两个表

java - spring认证管理器不绑定(bind)@Service注解的用户服务

java - 在 spring 中从 json 字符串创建模型时验证模型

java - Spring 中对 Map 的值进行 URLEncode

java - org.springframework.beans.factory.NoSuchBeanDefinitionException : No bean named 'itemAttrService' is defined

java - Spring HttpSessionListener 陷入循环

java - 运行 Spring Boot 集成测试时加载 ApplicationContext 失败

java - Spring RestTemplate 解析具有可变键名的 JSON 对象

java - 如何在不发送实体完整 json 的情况下更新对象