2011-05-25 110 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