【发布时间】:2017-08-06 11:58:09
【问题描述】:
通过查看 thymeleaf documentation,我尝试以这种方式在我的 Spring boot 项目中使用 thymeleaf 访问 Web 上下文对象:
<p th:text="${#request.getRequestURL()}">lol</p>
导致以下异常:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call:
Attempted to call method getRequestURL() on null context object
从这个错误看来,我可能缺少依赖项?我见过类似的question,解决方案是添加一个extras thymeleaf 包作为依赖项。
但是,在 thymeleaf 文档中声明这些对象和变量映射总是可以被调用,所以我想这里不应该是这种情况。
我正在使用 spring-boot-starter-thymeleaf 的 1.5.1 版以及许多其他 spring-boot-starter 软件包,例如 web 和 security。
【问题讨论】:
-
刚刚尝试过,使用
thymeleaf 3.0.2.RELEASE、thymeleaf-layout-dialect 2.1.1和spring boot 1.4.3.RELEASE可以正常工作。不需要额外的模块。 -
你是对的。发现访问 Web 上下文对象至少需要
thymeleaf-spring4:3.0.0.RELEASE和thymeleaf-layout-dialect 2.0.0。
标签: spring spring-boot thymeleaf