开发者

Can't get PropertyPlaceholderConfigurer to work

开发者 https://www.devze.com 2023-03-08 03:38 出处:网络
I am using LDAP to authenticate users in a web application. LDAP related beans are configured in a separate file named spring-servlet-security-ldap.xml (called ldap.xml now on). My main web applicatio

I am using LDAP to authenticate users in a web application. LDAP related beans are configured in a separate file named spring-servlet-security-ldap.xml (called ldap.xml now on). My main web application context file 'spring-servlet.xml' imports spring-servlet-security.xml which again imports the ldap file. This setup works if I do not use the properties file.

I've included the hierarchy details because similar question site PropertyPlaceholderConfigurer being overwritten as 开发者_Go百科the reason.

The properties file for ldap settings is placed in WEB-INF directory.

I've defined the PropertyPlaceholderConfigurer in ldap.xml as follows

<bean id="placeHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location"><value>WEB-INF/ldap.properties</value></property>
</bean>

I am referencing the properties in the same file

<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>

The logs indicate that the property is being loaded.

INFO Thread-0 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/ldap.properties]

But the property file is not being referenced for the value and literally configured value is being used. I've verified from the packet traces that the bind request goes for DN {ldap.userDN}.


I think you just need a $ sign for the placeholder: ${ldap.userDN}.

That is the placeholder format that PropertyPlaceholderConfigurer expects by default. This is controlled via the placeholderPrefix and placeholderSuffix properties; by default, ${ and } respectively.

0

精彩评论

暂无评论...
验证码 换一张
取 消