我正在使用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}
。
非常感谢。我不敢相信我浪费了很多时间在$以上。 – 2011-05-25 16:04:22