错误分析:template might not exist or might not be accessible by any of the configured Template Resolvers ......
原因一
/*controller*/
@GetMapping("/")
public String index(){
log.warn("访问了首页...");
return "index";
}
@GetMapping("login")
public String login(){
log.warn("访问了登录页面");
return "/pub/login";
}
说明:在idea中可以正常的访问,没有问题。当打长成jar时测试结果如下:
即:
- 首页可以正常访问
- 登录页访问异常:Exception processing template “/pub/login”: Error resolving template [/pub/login], template might not exist or might not be accessible by any of the configured Template Resolvers
- 解决方法:将
return "/pub/login";
改为return "pub/login";
即可
原因2
@GetMapping("about")
public String about(){
return "pub/about";
}
<!--about.html-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<link th:replace="~{/layout/resource.html::club-head}">
</head>
<body>
<main class="cd-main-content">
join us
</main>
</body>
</html>
说明:在idea中可以正常的访问,没有问题。当打长成jar时测试结果如下:
---------------------------------------------------------------------------------
- 有上面的原因1可以推测:controller没有问题,,即container所映射的?>about.html可以被找到;当却报错,那么问题就很有可能出现在about.html中
- 根据报错描述可知
在解析about.html
是报错。看细看一下就会发现一段报错描述:: Error resolving template [/layout/resource.html], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "pub/about" - line 4, col 12)
以此可以推测about.html中的<link th:replace="~{/layout/resource.html::club-head}">
导致的。注释掉它再打包测试就可以呢
- 解决方法:去掉前面的/.即:
<link th:replace="~{/layout/resource.html::club-head}">
修改为-><link th:replace="~{/ayout/resource.html::club-head}">
---------------------------------华丽的分割线------------------------------------
遗留问题
:
这里统一记录一下这两个问题,但对于其中原因:比如
- 为什么在idea中测试时没有抛出错误,而打包测试却报错了呢。