Spring Boot - Using Thymeleaf View

[Updated: Jan 26, 2018, Created: Jan 26, 2018]

To use Thymeleaf in Spring Boot application, we just need to include spring-boot-starter-thymeleaf dependency and place the template file under src/main/resources/templates/ directory. The rest of the configurations is done automatically by Spring Boot. Also check out our Thymeleaf example with plain MVC.


Maven dependencies


<project .....>

Thymeleaf Template File


<!DOCTYPE html>
<html xmlns=""

<h2>A Thymeleaf view</h2>
<div th:text="${msg}"/>
<div th:text="${time}"/>

Spring MVC Controller

public class MyController {

  public String handleRequest (Model model) {
      model.addAttribute("msg", "A message from the controller");
      return "my-page";

Spring boot main class

public class ExampleMain {

  public static void main(String[] args) throws InterruptedException {, args);

To try examples, run spring-boot maven plugin (configured in pom.xml of example project below):

mvn spring-boot:run

We can also run the main class from our IDE.


Example Project

Dependencies and Technologies Used:

  • spring-boot-starter-thymeleaf 1.5.9.RELEASE: Starter for building MVC web applications using Thymeleaf views.
    Corresponding Spring version: 4.3.13.RELEASE
  • JDK 1.8
  • Maven 3.3.9

Spring Boot - Thymeleaf View Example Select All Download
  • spring-boot-thymeleaf-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
          • templates

See Also