SpringBoot的MVC打包后的jar包在Linux上运行一段时间后,报错JSP: ClassNotFoundException问题解决

2022-07-10 89点热度 0人点赞 0条评论

问题描述

用SpringBoot写的MVC程序(内置Tomcat运行、View展示层用的JSP)打包成jar包,运行在Linux服务器上,刚开始没有什么问题,但是运行了一段时间后,总有几个页面点上去显示500错误。

查看日志,后台报错信息如下:

2022-07-09 11:47:17.296 [http-nio-8084-exec-5] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.system.modules_jsp] with root cause
java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.system.modules_jsp
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:129)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:58)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:158)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:192)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:111)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:111)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:111)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:711)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:385)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:313)
    at org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequestDispatcher.forward(HeaderWriterFilter.java:170)

解决办法

ClassNotFoundException后面跟着是那个jsp,系统找不到指定的jsp,经过研究和查阅方案,原因是jsp被编译后放在了tomcat临时文件,这个临时文件如果没有特别的配置,是放在/tmp/tomcat.123456目录(数字是随机生成的),Linux有定时清理/tmp目录下文件的机制,被清理后,springboot就找不到编译好缓存的jsp文件了。

我们可以在配置文件中指定这个tomcat临时文件地址,这样就不会被系统自动清理了。

配置application.properties 如下:

server.tomcat.basedir=/tmp/tomcat

或application.yml:

server:
  port: 8080
  tomcat:
    basedir: /tmp/tomcat

关于这个tomcat临时路径问题,之前也有遇到一个类似的问题,详见:Linux系统SpringBoot项目文件上传遇到The temporary upload location is not valid问题解决

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论