How to locate Thymeleaf template from spring boot


I am trying to follow this tutorial at to learn how to send responses to Thymeleaf template. But I get this error: Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)

I put the message.html file in Other Sources directory and inside src/main/resources under <default package>.

So the structure looks like :

-Other Sources
<default package>

I was wondering why it shows under <default package> but not under <template> ? Could it be the problem? If so how am I supposed to change it? I am using netbeans and maven. Any ideas please? These are the dependencies I have in my pom.xml:


In the controller I have

@RequestMapping(value = "message", method = RequestMethod.GET)
    public String messages(Model model) {
    model.addAttribute("messages", messageRepository.findAll());
    return "message";

And in the view:

<ul th:each="message : ${messages}">
    <li th:text="${}">1</li>
    <li><a href="#" th:text="${message.title}">Title ...</a></li>
    <li th:text="${message.text}">Text ...</li>


2 things here :
1. If you are using Maven, and I assume no customizations to folder names. Then the folder name should be src instead of source.
2. Once the folder has been renamed move your templates into ‘templates’ folder inside src/resources this should run fine.

Answered By – Himanshu Bhardwaj

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published