Spring Boot项目跑一段时间就出现了异常
1.异常
[/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid, e={} org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest. at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest. at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest. at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver. at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet. at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet. at at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet. at at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter. at org.apache.coyote.http11.Http11Processor.service(Http11Processor. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase. at at at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread. at Caused by: java.io.IOException: The temporary upload location [/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid at org.apache.catalina.connector.Request.parseParts(Request. at org.apache.catalina.connector.Request.parseParameters(Request. at org.apache.catalina.connector.Request.getParameterNames(Request. at org.apache.catalina.connector.Request.getParameterMap(Request. at org.apache.catalina.connector.RequestFacade.getParameterMap(RequestFacade. at org.springframework.web.servlet.DispatcherServlet.lambda$logRequest$2(DispatcherServlet. at org.springframework.core.log.LogFormatUtils.traceDebug(LogFormatUtils. at org.springframework.web.servlet.DispatcherServlet.logRequest(DispatcherServlet. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet. ... 34 common frames omitted 2020-02-17 10:45:29 -返回错误:code=999, msg=服务器出错了请稍后尝试.....
2.解决
1.SpringBoot项目运行一段时间上传文件出现这样的错误。
PS:错误信息很明显说是没有这个目录,linux过段时间就会自动清理一下tmp的一个临时目录,当然这个目录被清理的也就找不到了也就是报异常了
2.解决办法有3种:
1)mkdir -p /tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT
2)重启项目
3)自定义Tomcat的工作目录
在application.yml中增加以下配置,basedir后面跟一个“.”表示项目的启动目录。
server: tomcat: basedir: .