3

I am using Springboot 1.5.7 for my rest api application, and I am using thymeleaf template to send emails from my api. But when I updated the version of spring boot to 2.0.2 its throwing 404 error i.e "Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers".

Below is the config I have in application.yml

spring: thymeleaf: cache: false enabled: true mode: HTML5 prefix: /templates/ suffix: .html 

thymeleaf version in pom.xml

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

Below is the template structure i am using,

enter image description here

My app release is very near and I am badly stuck with this problem, if someone can provide me workaround then it would be a great help.

1
  • Did you solve your problem? you should accept the answer if it solved. Commented Jun 3, 2018 at 13:00

2 Answers 2

5

Remove prefix: /templates/ from application.yml

If still does not work, add thymeleaf-layout-dialect dependency (See: Thymeleaf stopped resolving layout templates after migrating to Thymeleaf 3)

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nz.net.ultraq.thymeleaf</groupId> <artifactId>thymeleaf-layout-dialect</artifactId> </dependency> 

FYI, I put my views in WEB-INF/webapp/views, so I am using prefix: /WEB-INF/webapp/views/ (spring boot war deploy to tomcat)

Sign up to request clarification or add additional context in comments.

Comments

4

As stated in the 2.0 migration guide.

The Thymeleaf starter included the thymeleaf-layout-dialect dependency previously. Since Thymeleaf 3.0 now offers a native way to implement layouts, we removed that mandatory dependency and leave this choice up to you. If your application is relying on the layout-dialect project, please add it explicitly as a dependency.

Adding the following dependencies should work

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nz.net.ultraq.thymeleaf</groupId> <artifactId>thymeleaf-layout-dialect</artifactId> </dependency> 

SOURCE : https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#template-engines

1 Comment

Not adding dependency of layout-dialect will cause a problem to resolve layout template, not 404. And how is your answer different than the first one (thymeleaf-layout-dialect dependency also mentioned there)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.