Spring Boot Thymeleaf Hello World Example

Spring Boot Thymeleaf Hello World Example walks you through the process of creating a example spring boot with Thymeleaf template engine step by step. Spring Boot is sub-project developed by developers of spring framework, Spring Boot makes it easy to create stand-alone, production-grade Spring based applications with minimum configuration possible. This tutorial is quite familiar to the tutorial Spring Boot Maven Example Hello World with JSP.

Other interesting posts you may like

Let’s begin:

Project structure
We will create a project with directory structure like below

Spring Boot Thymeleaf Hello World Example

Maven Dependencies
To create Spring Boot Thymeleaf Hello World Example, you need to add dependencies into pom.xml file like below:

Let’s dig deeper:

We are developing a web application so we will add a spring-boot-starter-web dependency in pom.xml like below:
In order to enable Thymeleaf support we need to add dependencies into pom.xml like below:

In this example, we are using maven plugin so we need to add the below dependency into pom.xml file:

Configure Spring Web Application
To set our application up as a servlet application we extend our main class with SpringBootServletInitializer and override the configure method using SpringApplicationBuilder.

But by default, Thymeleaf caches the templates, we need to change this behaviour in order to update Thymeleaf templates by setting application.properties file in src/main/resources directory like below:

Create the Controller
We create a simple controller named HelloWorldController like below.

Create the Thymeleaf template

Create index page using Thymeleaf

Create a template using Thymeleaf to display “Hello World” words and other message.

Run Application
To deploy and run our Spring Boot Thymeleaf Hello World Example on web container, we run the below command in console

Note: You must be in your project directory before run that command.
While running that command, you will see the output like below

Spring Boot Thymeleaf Hello World Example

After running successfully, you can access the application via URL http://localhost:8080 and see the homepage such as

Spring Boot Thymeleaf Hello World Example

Click the link “Click me to say Hello” then the Hello World page is displayed

Spring Boot Thymeleaf Hello World Example

That’s it on the tutorial Spring Boot Thymeleaf Hello World Example.

Download complete source code, please click link below

SpringBoot-Thymeleaf-Example.zip (62 downloads)

2 thoughts on “Spring Boot Thymeleaf Hello World Example

Leave a Comment

*

Please share it if you found this useful
Hide Buttons