问题:使用本地ide启动项目在浏览器中可以正常访问项目中的每个页面,但是把项目打包成jar包后再部署到服务器中后有一个始终页面initRfid.html无法访问成功,浏览器控制台报错500,再到后台日志中查看错误:
大概意思就是thymeleaf无法找到该页面
16:52:21.509 [https-jsse-nio-400-exec-22] ERROR o.t.TemplateEngine - [process,1136] - [THYMELEAF][https-jsse-nio-400-exec-22] Exception processing template "process/initRfid/add": Error resolving template [process/initRfid/add], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [process/initRfid/add], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
奇怪的是其他页面相同的的写法,均可以正常访问。经过仔细对比后,项目中存放initRfid页面的文件夹是initRfid,而在后台控制器controller中给出的页面路径却是initRFID,这就造成了thymeleaf无法找到该页面的结果。如果数据库中也有页面路径的话记得同时修改!
总结:在ide中运行项目却可以忽略文件夹的大小写。而在生产环境的服务器一定要注意项目中文件夹以及路径的大小写。