无法使PropertyPlaceholderConfigurer工作

Lal*_*hra 2 spring

我正在使用LDAP来验证Web应用程序中的用户.LDAP相关bean在一个名为spring-servlet-security-ldap.xml(ldap.xml现在称为on)的单独文件中配置.我的主Web应用程序上下文文件'spring-servlet.xml'导入spring-servlet-security.xml,它再次导入ldap文件.如果我不使用属性文件,此设置有效.

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

ldap设置的属性文件放在WEB-INF目录中.

我已经定义了PropertyPlaceholderConfigurerldap.xml如下

<bean id="placeHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location"><value>WEB-INF/ldap.properties</value></property>
</bean>
Run Code Online (Sandbox Code Playgroud)

我在同一个文件中引用属性

<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>
Run Code Online (Sandbox Code Playgroud)

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

INFO Thread-0 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/ldap.properties]
Run Code Online (Sandbox Code Playgroud)

但是没有为该值引用属性文件,并且正在使用字面配置的值.我已经从数据包跟踪验证了绑定请求是针对DN的{ldap.userDN}.

Cos*_*atu 6

我想你只需要一个$占位符的标志:${ldap.userDN}.

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