Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access system properties in Thymeleaf template?

I need to access system properties in a Thymeleaf template. It would be nice if this was possible so that I don't have to populate the spring mvc model explicitly with properties. I'm trying to use SPEL for this purpose but it's not working.

<h2 th:text="${ systemProperties['serverName'] }">Service name</h2>

<h2 th:text="*{ systemProperties['serverName'] }">Service name</h2>

Both of these give me:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1012E:(pos 17): Cannot index into a null value

Even if I try to access a jdk property it gives the same error so I know it's not the fact that the property is missing. What am I doing wrong or is there another way to do this?

like image 692
junkie Avatar asked Feb 12 '14 11:02

junkie


People also ask

How do I check my Thymeleaf configuration?

Thymeleaf template files are located in the custom src/main/resources/mytemplates directory. The default template directory is src/main/resources/templates . This is the Maven build file. The spring-boot-devtools enables hot swapping, disables template cache and enables live reloading.

How do you get the model attribute in Thymeleaf?

In Thymeleaf, these model attributes (or context variables in Thymeleaf jargon) can be accessed with the following syntax: ${attributeName} , where attributeName in our case is messages .

How do you display value in Thymeleaf?

The return value of our controller's method should be the name of the desired Thymeleaf template. This name should correspond to the HTML file located in the src/resource/template directory. In our case, it'll be src/resource/template/articles-list. html.


1 Answers

I use

${@environment.getProperty('myPropertyName')}
like image 173
Dave Bower Avatar answered Sep 30 '22 06:09

Dave Bower