Escape property reference in Spring property file

Stephane picture Stephane · Oct 31, 2012 · Viewed 7.4k times · Source

I want to escape my Spring propeties file in order to get in my bean property: ${ROOTPATH}/relativePath

I have a simple Spring config file that contains:

<context:property-placeholder location="classpath:myprops.properties" />

<bean id="myBean" class="spring.MyBean">
    <property name="myProperty" value="${myproperty}" />
</bean> 

The myprops.properties contains:

myproperty=\${ROOTPATH}/relativePath

The above setup returns: Could not resolve placeholder 'ROOTPATH'. I tried a lot of possible syntaxes but was not able to find the right one.

Answer

user2428804 picture user2428804 · Jan 22, 2014

Instead of ${myproperty} use #{'$'}{myproperty}. Simply replace $ with #{'$'}.