Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape property reference in Spring property file

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.

like image 223
Stephane Avatar asked Oct 31 '12 16:10

Stephane


2 Answers

Seems so far, that is no way to escape the ${}, however you can try below configuration to solve the problem

dollar=$

myproperty=${dollar}{myproperty}

Result for myproperty will be ${myproperty} after evaluation.

like image 107
Allen Ai Avatar answered Sep 19 '22 12:09

Allen Ai


Here is a Spring ticket which asks for escaping support (still unresolved at the time of writing).

The workaround of using

$=$
myproperty=${$}{ROOTPATH}/relativePath

does provide a solution, but looks quite dirty.

Using SPEL expressions like #{'$'} did not work for me with Spring Boot 1.5.7.

like image 41
Christian Avatar answered Sep 22 '22 12:09

Christian