0

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.

halfdark
  • 50
  • 8

1 Answers1

0

The following worked for me:

template:#{'$'}{now}

Original answer here

kosmasd
  • 316
  • 1
  • 5
  • Someone has already answered in my question and given the Original answer link before , I don't know why he deleted the answer. Besides, this not work for me, but `@Value("#{'$'}{myTemplate}")` this works for me – halfdark Apr 22 '22 at 05:46