1 pièce(s) jointe(s)
Thymeleaf: Exception processing template
Bonjour à tous,
j'ai suivi le cours de serge Tahé en vue de faire un projet spring mvc avec Thymeleaf.
La démarche est également valable dans la documentation officielle de Spring Tools Suite.
Ainsi
- Avec Spring Tools Suite sur un nouvel espace de travail
- Menu 'Fichier > Nouveau > Importer le contenu de mise en route'
- Sélectionnez le guide "Servir du contenu Web"
- Laissez tous les autres paramètres de l'assistant par défaut
Cliquez sur Terminer
Une fois le projet importé et construit par l'outil et tous ...
Après exécution en tant que "Application Spring Boot"
lorsque je sollicite la page localhost:9000/sprgvues/v01 ou localhost:9000/sprgvues/v01.html
le serveur me donne
Citation:
[THYMELEAF][http-nio-9000-exec-3] Exception processing template "/v03": An error happened during template parsing (template: "class path resource [templates//v03.html]" - line 1, col 1)
Pièce jointe 597376
- Le contenu du fichier POM.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ubi.ubisys.sprgvues</groupId>
<artifactId>sprgvues</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sprgvues</name>
<description>Les vues dans Spring MVC</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
...
</dependencies>
...
</project> |
- application.properties:
Code:
1 2
| server.port=9000
server.servlet.context-path=/sprgvues |
- Le contenu de templates:
\templates
|-v01.html
|-v02.html
|-v03.html
- ViewController.java :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package ubi.ubisys.sprgvues.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import ubi.ubisys.sprgvues.models.Personne;
@Controller
public class ViewsController {
// Les bases de Thymeleaf - 1
@RequestMapping(value = "/v01", method = RequestMethod.GET)
public String v01() {
return "/v01.html";
}
// Les bases de Thymeleaf - 2
@RequestMapping(value="/v02", method = RequestMethod.GET)
public String v02() {
System.out.println("action v02");
return "/v02";
}
// Internationalisation des vues
@RequestMapping(value="/v03", method = RequestMethod.GET)
public String v03() {
return "/v03";
}
// Création du modèle M d'une vue V
@RequestMapping(value = "/v04", method = RequestMethod.GET)
public String v04(Model model) {
model.addAttribute("personne", new Personne(7,"martin",17));
System.out.println(String.format("Modèle=%s" ,model));
return "v04";
}
} |
En fait tout roule (toutes les vues dans static s'affichent) tandis que ceux dans templates ne passent pas comme indiqué sur l'image.
Le log de Spring donne:
Citation:
021-05-07 05:10:01.447 ERROR 71094 --- [nio-9000-exec-3] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-9000-exec-3] Exception processing template "/v01": An error happened during template parsing (template: "class path resource [templates//v03.html]" - line 1, col 1)
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates//v01.html]" - line 1, col 1)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:239) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] ...
J'ai parcourue la documentation en vain.
Pour rappel, j'utilise sdk 1.8.
Merci d'avance.