Home > Back-end >  How to set a value with '$' in content of a @Value in Spring
How to set a value with '$' in content of a @Value in Spring

Time:04-20

It's a common way to use @Value in Spring to load value from propertie files, like: @Value("${xxxx}")

Now I come cross a situation that I need to set the content of value like ".... now: ${now}...." , because I need to use it as a template in org.beetl.core.GroupTemplate

here is the example:

@Value("${myTemplate}")
private String myTemplate;

and the application.properties:

myTemplate = template:${now}

then Spring find the $ in ${now} and parsing it as a placeholder and give the error:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'now' in value

And I'm not willing and able to set setIgnoreUnresolvablePlaceholders to false;

Also I tried to replace the content to ....now:${now}...., however I tried many ways to convert the $ to $ in java code, but none of them worked;

So is there any other ways to deal with this case?

Thanks for your helping and time.

CodePudding user response:

Do you want to use $ in an HTML/JSP? Could you please describe more details in your question?

Inside the $ should be a property key for example

@Value("${my.property.key:default}")
String myValue
  • Related