Search code examples
spring-bootthymeleaf

Spring Boot 2.4.2 and Thymeleaf 3.0.12 - access static methods


Since I switched to Spring Boot 2.4.2 my Thymeleaf templates are broken. When I want to access a static member in Spring Controller I get the following error:

Exception processing template "template_name": Instantiation of new objects and access to static classes is forbidden in this context.

The code looks like: th:text="${T(com.test).testMethod("1234")}"

Do you have any recommendation to fix this?


Solution

  • This change is the part of Thymeleaf 3.0.12. They improve restricted expression evaluation mode security by restriction of the access to static code (@identifier@ in OGNL, T(identifier) in SpringEL). What they have done by themselves? ... "Avoided instantiation of new objects and calls to static classes" as stated in release notes. You may move the JAVA calls into your controller and put the result into the view model. After just access this variable from Thymeleaf template.