template might not exist or might not be accessible by any of the configured Template Resolvers (tem

错误分析: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中测试时没有抛出错误,而打包测试却报错了呢。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值