org.thymeleaf.exceptions.TemplateInputException

本地开发环境没有任何问题,但是打成jar部署到服务器时,就出现异常信息了,以为没有把模板文件打入到jar中,可以通过jar xvf spring-boot-thymeleaf-0.0.1-SNAPSHOT.jar 查询jar中的内容,可以看到我们的模板文件。

后台异常信息
1 | 2018-02-06 23:06:39.547 ERROR 13904 --- [p-nio-80-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/index", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause |
项目结构如下图
问题代码
1 |
|
仔细排查后发现是return "/demo/01";这行代码多了个/,去掉/搞定。
示例代码
https://github.com/ncc0706/spring-boot-demos/tree/master/spring-boot-thymeleaf