2011-05-25 108 views
2

我正在使用LDAP来验证Web应用程序中的用户。与LDAP相关的bean被配置在名为spring-servlet-security-ldap.xml(现在称为ldap.xml)的单独文件中。我的主Web应用程序上下文文件'spring-servlet.xml'导入spring-servlet-security.xml,它再次导入ldap文件。如果我不使用属性文件,这个设置工作。无法让PropertyPlaceholderConfigurer工作

我已经包含层次结构详细信息,因为类似问题网站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] 

但属性文件没有被引用的值和字面上配置的值正在使用。我已经从数据包跟踪中证实绑定请求适用于DN {ldap.userDN}

回答

6

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

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

+0

非常感谢。我不敢相信我浪费了很多时间在$以上。 – 2011-05-25 16:04:22