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

Stella981
• 阅读 1138

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

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

问题:

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

Exception:

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

thymeleaf 配置:

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

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

Controller:

    @Resource
    private UserDao userDao;

    @RequestMapping("/q")
    public ModelAndView index() {
//        String sql = "select name, age from user";
//        ModelAndView modelAndView = new ModelAndView("/bug");
//        modelAndView.addObject("data",jdbcTemplate.queryForList(sql));

        ModelAndView modelAndView = new ModelAndView("/bug");
        PageHelper.startPage(1,2);
        modelAndView.addObject("data",userDao.query());
        return modelAndView;
    }

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

解决:

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

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

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
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
红烧土豆泥 红烧土豆泥
2年前
Spring Boot:jar中没有主清单属性
使用SpringBoot微服务搭建框架时,使用IDEA可以正常运行,但是使用MAVEN打包工具打包成jar后运行时,提示错误:未找到主清单目录。查看pom文件,发现已添加SpringBoot的构建插件xmlorg.springframework.bootspringbootmavenplugin2.4.1
Easter79 Easter79
2年前
thymeleaf在工作中常用的属性及表达式使用详解(一)
最近在写微服务的项目,第一次接触thymeleaf,踩了很多雷,决定把我在工作中遇到的跟大家分享,希望能帮助遇到相同问题的朋友。1.1 首先介绍一下这个东西(来源百度)http://www.thymeleaf.org 这是thymeleaf的官网。(https://ww
Stella981 Stella981
2年前
SpringBoot打成jar包后,获取不到读取resources目录下文件路径的问题
问题描述:Springboot没有打成jar之前,可以成功获取读取resources目录下xxx.json文件的路径。但是打成jar包后,接口调不通,原因是获取不到文件的路径。原因:在本地进行调试时,文件是真实存在于磁盘的某个目录。此时通过获取文件路径,是可以正常读取的,因为文件确实存在。而打包成jar以后,实际上文件是
Easter79 Easter79
2年前
SpringBoot2.x打包成war(看这篇就够了)
springboot默认打包成jar,如果想打包成war,则需要做以下三步。1.修改pom.xml文件  a.将jar改成war1<groupIdcom.test</groupId2<artifactId01springbootHelloWorld</artifactId3<versi
Stella981 Stella981
2年前
SpringBoot2.0 基础案例(17):自定义启动页,项目打包和指定运行环境
本文源码GitHub地址:知了一笑https://github.com/cicadasmile/springbootbase一、打包简介springboot的打包方式有很多种。可以打war包,可以打jar包,可以使用jekins进行打包部署的。不推荐用war包,SpringBoot适合前后端分离
Easter79 Easter79
2年前
SpringBoot2.0 基础案例(17):自定义启动页,项目打包和指定运行环境
本文源码GitHub地址:知了一笑https://github.com/cicadasmile/springbootbase一、打包简介springboot的打包方式有很多种。可以打war包,可以打jar包,可以使用jekins进行打包部署的。不推荐用war包,SpringBoot适合前后端分离
Wesley13 Wesley13
2年前
Java初级开发0608面试
聊聊SpringBoot和传统的SSM的区别?SpringBoot是Spring的扩展,在Spring的基础上,简化了传统的SSM开发繁琐的配置;在部署上,SpringBoot内置了Tomcat,可以直接将项目打包成可执行的jar/war。说说你了解的Docker?
Stella981 Stella981
2年前
SpringBoot2.x打包成war(看这篇就够了)
springboot默认打包成jar,如果想打包成war,则需要做以下三步。1.修改pom.xml文件  a.将jar改成war1<groupIdcom.test</groupId2<artifactId01springbootHelloWorld</artifactId3<versi
Stella981 Stella981
2年前
Image Upload based on jQuery
今天把自己写的一个简单的jQuery上传插件放到了Git@OSC上了,希望能帮助需要的人,并且得到高人的指点,一起用心的维护下去。戳这里((https://git.oschina.net/GoodLoser/ImageUploader)http://git.oschina.net/GoodLoser/iUploader(http://git.osch