spring-boot - Spring Boot 2.4.2 和 Thymeleaf 3.0.12 - 访问静态方法

标签 spring-boot thymeleaf

因为我切换到 Spring Boot 2.4.2 我的 Thymeleaf 模板坏了。当我想访问 Spring Controller 中的静态成员时,出现以下错误:

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


代码如下:th:text="${T(com.test).testMethod("1234")}"你有什么建议来解决这个问题吗?

最佳答案

此更改是 Thymeleaf 3.0.12 的一部分。它们通过限制访问静态代码(OGNL 中的@identifier@,SpringEL 中的 T(identifier))来限制它们的 improve restricted expression evaluation mode security。他们自己做了什么? ...“避免了新对象的实例化和对静态类的调用”,如发行说明中所述。您可以将 JAVA 调用移动到您的 Controller 中并将结果放入 View 模型中。从 Thymeleaf 模板访问此变量后。

关于spring-boot - Spring Boot 2.4.2 和 Thymeleaf 3.0.12 - 访问静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66048129/

相关文章:

spring - Autowiring 到 JPA 转换器

java - 无法写入 ID 为 0 的 JSON : Unable to find com. demo.model.Control;

Spring Boot 安全性 - 多个身份验证提供程序

spring - ThymeLeaf - 将表数据(ArrayList)发布到另一个 Controller

java - Thymeleaf,不要在数字中插入换行符

java - 为什么不需要通过配置公开 JavaMailSender 即可 Autowiring ,Spring Boot 1.5.8

tomcat - Spring Boot 启动失败

javascript - 尝试将 React/Ajax 调用与 Spring MVC 和 Thymeleaf 结合使用

java - 需要有关 Java、JPA、Thymeleaf 和 Mysql 的帮助

html - Thymeleaf 异常解析文档 - Css 模板