I'm trying to add a header to all the pages of my Spring Boot application, so I want to use Thymeleaf to add this layout.
But when I'm trying to access my home page for exemple, I get this error message :
Error resolving template [accueil], template might not exist or might not be accessible by any of the configured Template Resolvers
I looked through internet and found some advices to fix this issue, but none of them worked...
My layout path is : src/main/resources/templates/layout.html
so I tried to add these prefix and suffix to my application.properties
file :
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
But it don't works...
Here are my layout.html file, my home controller and my pom.xml file :
layout.html :
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Enums in Thymeleaf</title>
</head>
<body>
<h2>Hello from layout</h2>
</body>
</html>
AccueilControleur :
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AccueilControleur {
@GetMapping("")
public String index(){
return "accueil";
}
}
pom.xml dependencies :
<dependencies>
<!-- Pour Spring Boot, ajoutez ceci dans la section <dependencies> de votre pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>
Did someone have an idea on that issue ?
Best regards