Escape property reference in Spring property file

青春壹個敷衍的年華 提交于 2019-11-28 07:22:06

问题


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.


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/13162346/escape-property-reference-in-spring-property-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!