Error: Attempted to call method "format" on null context object
If you use springboot and configuration as code
add : templateEngine.addDialect(new Java8TimeDialect());
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>