Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set a value with '$' in content of a @Value in Spring

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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.

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading