在Spring Boot项目中,无法使用Thymeleaf访问Web上下文对象



从查看百里叶文档中,我尝试以这种方式在我的春季启动项目中使用胸腺上下文对象访问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

由于这个错误,我似乎可能缺少依赖性吗?我已经看到了一个类似的问题,解决方案是在哪里添加extras ThymeLeaf软件包作为依赖。

但是,在百里香文档中指出,这些对象和可变地图始终可被调用,所以我想这里不应该这样。

我正在使用spring-boot-starter-thymeleaf的版本1.5.1以及许多其他spring-boot-starter软件包,例如websecurity

我让它与thymeleaf-spring4:3.0.0.RELEASEthymeleaf-layout-dialect 2.0.0一起使用,因此似乎是所需的最低版本。

spring-boot-starter-thymeleaf:1.5.1.RELEASE仅提供thymeleaf-spring4:2.1.5.RELEASEthymeleaf-layout-dialect 1.4.0

最新更新