SpringBoot 打包 jar 后执行 thymeleaf 提示找不到模版

基于懒,花了点时间研究了一下 SpringBoot,个人觉得也就是一个懒人版的 SS 框架

我的 demo git 地址:http://git.oschina.net/zgdhd/my-springboot 希望里面的注释能帮助初学的师弟

问题:

打包成 jar 在终端运行启动后访问页面提示找不到 thymeleaf 模版!!

Exception:

114:13:58.749 logback [http-nio-8080-exec-1] INFO org.thymeleaf.TemplateEngine - [THYMELEAF] TEMPLATE ENGINE INITIALIZED 214:13:58.840 logback [http-nio-8080-exec-1] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8080-exec-1] Exception processing template "/bug": Error resolving template "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers 314:13:58.847 logback [http-nio-8080-exec-1] ERROR 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 "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause 4org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers 5 at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) 6 at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) 7 at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) 8 at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011) 9 at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335) 10 at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190) 11 at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) 12 at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) 13 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) 14 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) 15 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)

thymeleaf 配置:

Controller:

1 @Resource 2 private UserDao userDao; 3 4 @RequestMapping("/q") 5 public ModelAndView index() { 6// String sql = "select name, age from user"; 7// ModelAndView modelAndView = new ModelAndView("/bug"); 8// modelAndView.addObject("data",jdbcTemplate.queryForList(sql)); 9 10 ModelAndView modelAndView = new ModelAndView("/bug"); 11 PageHelper.startPage(1,2); 12 modelAndView.addObject("data",userDao.query()); 13 return modelAndView; 14 }

在 Idea 里面完美运行!狗日的打包成  jar 后就报 bug!!

解决:

把 Controller -> ModelAndView 里面的地址中的斜杠“/”去掉!(“/bug” --> “bug”)

我去,这坑定的....习惯....习惯在SS里面跳转地址的时候都要加一个斜杠~~

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java Excel导入导出,基于XML的实现,easy

项目地址:http://git.oschina.net/lis1314/easyexcel(http://git.oschina.net/lis1314/easyexcel)springboot使用例子:https://gitee.com/lis1314/easyexceldemo(https://gitee.com/lis1314/e

thymeleaf在工作中常用的属性及表达式使用详解(一)

最近在写微服务的项目,第一次接触thymeleaf,踩了很多雷,决定把我在工作中遇到的跟大家分享,希望能帮助遇到相同问题的朋友。1.1 首先介绍一下这个东西(来源百度)http://www.thymeleaf.org 这是thymeleaf的官网。(https://ww

Spring Boot:jar中没有主清单属性

使用SpringBoot微服务搭建框架时,使用IDEA可以正常运行,但是使用MAVEN打包工具打包成jar后运行时,提示错误:未找到主清单目录。查看pom文件,发现已添加SpringBoot的构建插件xmlorg.springframework.bootspringbootmavenplugin2.4.1

SpringBoot2.x打包成war(看这篇就够了)

springboot默认打包成jar,如果想打包成war,则需要做以下三步。1.修改pom.xml文件  a.将jar改成war1<groupIdcom.test</groupId2<artifactId01springbootHelloWorld</artifactId3<versi

SpringBoot2.0 基础案例(17):自定义启动页,项目打包和指定运行环境

本文源码GitHub地址:知了一笑https://github.com/cicadasmile/springbootbase一、打包简介springboot的打包方式有很多种。可以打war包,可以打jar包,可以使用jekins进行打包部署的。不推荐用war包,SpringBoot适合前后端分离