Quick tip – How to use Thymeleaf 3 with Spring Boot

Spring Boot, by default, uses Thymeleaf 2 as its template engine. You can, however, make it use the newer version.

First, you must add the following properties to your pom.xml:

<properties>
    <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
    <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>

This might be enough, depending on whether or not you use any Thymeleaf “extras”. If you do, you must also remember to specify a version for them, as the version inherited from Spring Boot will most likely be too low. Here’s an example for Thymeleaf’s “extras” integration module for Spring Security 1.4:

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>3.0.2.RELEASE</version>
</dependency>

When you start your application, you will now get the following message in your logs:

[THYMELEAF][main] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.

To get rid of it, you must add the following line to your application.properties file:

spring.thymeleaf.mode: HTML

For more information on using Thymeleaf 3 with Spring Boot, you can visit the official documentation.

Daniel Frąk Written by:

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *