Skip to content
Advertisement

Error resolving fragment template Spring Boot using Thymeleaf

I have a Spring Boot application using Thymeleaf, it works fine when using mvn spring-boot:run but when deploying it into the JAR file it gives me an error for all files that have th:replace statement for example templates/web/index in line: <div th:replace="/web/includes/header :: header"></div>

The exception when trying to run java -jar my-app.jar

JavaScript

My project resources hierarchy

enter image description here

My resources locations

enter image description here

ClassLoaderTemplateResolver

enter image description here

Advertisement

Answer

Instead of /web/includes/header, use web/includes/header. In the jar, the file are evaluated from the templates folder. Being in the folder templates, the path /web/includes/header is invalid.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement