Labs ICT
Pro Login

Setting Up Thymeleaf

Thymeleaf with Spring Boot in minutes.

Setting Up Thymeleaf

Let's get Thymeleaf running in your Spring Boot project. The setup is dead simple — Spring Boot makes it almost automatic.

Add the Dependency

First, add the Thymeleaf starter to your pom.xml. That's all you need for Maven projects.


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
    

For Gradle, add this to your build.gradle:


implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    

Template Directory

By default, Spring Boot looks for templates in the src/main/resources/templates/ folder. Create that folder if it doesn't exist. Put all your Thymeleaf HTML files there.


src/
  main/
    resources/
      templates/
        index.html
        about.html
        home.html
    

That's the convention. Stick with it and everything just works.

Application Properties

You usually don't need to change anything in application.properties. But if you want to customize the template prefix or suffix, here's how:


spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
    

Set cache=false during development so you don't have to restart the server every time you change a template. Turn it back on for production.

Try it Yourself →