Error: Attempted to call method “format” on null context object

跟風遠走 提交于 2019-12-05 05:58:41

To use #temporals object you need include thymeleaf-extras-java8time module to your project. Here is GitHub page of the extras module.

This module adds a #temporals object similar to the #dates or #calendars ones in the Standard Dialect, allowing the formatting and creation of temporal objects from Thymeleaf templates.

In version 1.4.1 of Spring Boot it is only necessary to include the extras module, and autoconfiguration will set up it for you. Make sure that you provided the proper version, depends on your Thymeleaf version:

  • Version 3.0.0.RELEASE - for Thymeleaf 3.0 (requires Thymeleaf 3.0.0+)
  • Version 2.1.0.RELEASE - for Thymeleaf 2.1 (requires Thymeleaf 2.1.3+)

I've got the same spring boot and thymeleaf versions as you and have received the same error just because I provide inappropriate version of extras (3.0.0). Switching it to lower version fixed the problem (in my case in maven pom file):

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
    <version>2.1.0.RELEASE</version>
</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!