Error cause and how to deal with it|Spring Boot+Thymeleaf|TemplateInputException| template might not exist or might not be accessible...|Template access error



When I created a Spring Boot project jar file in Eclipse and ran it at the command prompt, an error occurred.



Here, we will introduce the details of the error that occurred and how to deal with it.

* In Eclipse, when I right-clicked the project → Selected "Run" > "Spring Boot Application" and ran it, no error occurred, but when I ran the jar file, an error occurred.

Environment

・Windows 10 64bit
・Java 8
・Spring Boot 2.1.3(Spring Tool Suite 4)
・Maven 3.5.3
・Thymeleaf 3.0.11

Error information that occurred

Error information - Check the content output to the command prompt

When I executed the Spring Boot jar file at the command prompt, the following error was output to the command prompt

・Execution command
java -jar XXX.jar

・Error information
2019-05-01 13:28:22.161 ERROR 8224 --- [nio-8080-exec-3] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-3] Exception processing template "/customer/list": Error resolving template [/customer/list], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/customer/list], template might not exist or might not be accessible by any of the configured Template Resolvers


Cause

There is a problem with the source code of the controller class,
An error occurred because the view stored in the folder "customer" under "/src/main/resources/templates" could not be accessed.



・Source code (controller class)
@GetMapping("/customer/list")

public String list() {


    return "/customer/list";

}

How to respond

Modify the controller class source code as follows.

The above source code
return "/customer/list";

return "customer/list";
to correct.

・Supplement

For redirects, a leading "/" is required.
return "redirect:/customer/list";
If there is no "/" at the beginning, as shown below, an error will occur.

return "redirect:customer/list";

Rreference


Cannot access templates running Spring Boot with JAR



スポンサーリンク

0 件のコメント :

コメントを投稿