by Rafał Borowiec

Menu

Wednesday, November 11, 2015

If you happen to work with Spring Boot and Thymeleaf and you need to format Java 8 Date & Time objects in your views you may utilize thymeleaf-extras-java8time - Thymeleaf module for Java 8 Date & Time API.

Once you have done it, the next step is to add the dialect to the template engine. With Spring Boot you need to define a bean of type org.thymeleaf.extras.java8time.dialect.Java8TimeDialect in your appliacation context. All beans of type org.thymeleaf.dialect.IDialect are injected into Spring Boot’s ThymeleafAutoConfiguration and added to Thymeleaf’s SpringTemplateEngine automatically.

Note (24/9/2016) Spring Boot introduced org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.ThymeleafJava8TimeDialect class that auto-configures the dialect if Java 8 is available and org.thymeleaf.extras.java8time.dialect.Java8TimeDialect is on the classpath. So the below configuration is not needed anymore if you are using newest Spring Boot.

temporals provide many utility method to work with java.time.Temporal: formatting, accessing properties and creating new objects. For more information about the extension and temporals itself checkout project page on GitHub: thymeleaf-extras-java8time