【问题标题】:Cannot access web context objects with thymeleaf in Spring boot project在 Spring Boot 项目中无法使用 thymeleaf 访问 Web 上下文对象
【发布时间】: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 软件包,例如 websecurity

【问题讨论】:

  • 刚刚尝试过,使用thymeleaf 3.0.2.RELEASEthymeleaf-layout-dialect 2.1.1spring boot 1.4.3.RELEASE 可以正常工作。不需要额外的模块。
  • 你是对的。发现访问 Web 上下文对象至少需要 thymeleaf-spring4:3.0.0.RELEASEthymeleaf-layout-dialect 2.0.0

标签: spring spring-boot thymeleaf


【解决方案1】:

我让它与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

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2017-03-20
    • 2017-06-29
    • 2020-01-04
    • 2022-01-22
    • 2017-08-14
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    相关资源
    最近更新 更多