Thymeleaf Example with Spring Boot

In this tutorial, we will learn how to create a simple Hello World Thymeleaf App with Spring boot.

Spring Boot aims to make it easy to create Spring-powered, production-grade applications and services with minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need.
Thymeleaf is a Java-based library used to create a web application. It provides good support for serving an XHTML/HTML5 in web applications.
Learn spring boot at

Development Steps

1. Create a Spring Boot Application

There are many ways to create a Spring Boot application. You can refer below articles to create a Spring Boot application.

2. Add Maven Dependencies

<?xml version="1.0" encoding="UTF-8"?>
        <relativePath />
        <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot Thymeleaf and Hibernate </description>
Spring boot uses below dependency to work with Thymeleaf:

3. Spring MVC Controller -

package net.javaguides.springboot;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

public class HelloWorldController {

    public String hello(Model model) {
        model.addAttribute("message", "Hello World!");
        return "helloworld";

4. Thymeleaf ViewResolver Configuration

Spring boot will auto-configure view resolver for Thymeleaf whenever it will find the springboot-thymeleaf-starter dependency on classpath. Spring boot will pick Thymeleaf templates (HTML pages) from resources/templates folder.

5. Thymeleaf Template - helloworld.html

<!DOCTYPE html>
<html xmlns:th="">
<meta charset="ISO-8859-1">
<title>Hello World App</title>
 <h1 th:text="'Thymeleaf ' + ${message} + ' App'"> </h1>

6. Run app and demo

Let's run this spring boot application from IDE -> Right-click -> Run As -> Java Application:
package net.javaguides.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringbootThymeleafHelloWorldExampleApplication {

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

Related Thymeleaf Tutorials and Examples

  1. Introducing Thymeleaf | Thymeleaf Template | Thymeleaf Template Engine
  2. Thymeleaf Example with Spring Boot
  3. How to Add CSS and JS to Thymeleaf
  4. Add Bootstrap CSS to Thymeleaf
  5. How to handle null values in Thymeleaf?
  6. How to Loop a List by Index in Thymeleaf
  7. Thymeleaf Array Example - Array Index, Array Iteration
  8. Thymeleaf Enums Example
  9. Thymeleaf If Else Condition Example
  10. Thymeleaf Switch Case Example