org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes

简介: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes

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: .
相关文章
|
30天前
|
XML 存储 Java
11:Servlet中初始化参数的获取与应用-Java Web
11:Servlet中初始化参数的获取与应用-Java Web
45 3
|
20天前
|
存储 Java 应用服务中间件
Servlet执行流程&生命周期&方法介绍&体系结构、Request和Response的功能详解(2)
Servlet执行流程&生命周期&方法介绍&体系结构、Request和Response的功能详解
26 2
|
20天前
|
Web App开发 XML Java
Servlet执行流程&生命周期&方法介绍&体系结构、Request和Response的功能详解(1)
Servlet执行流程&生命周期&方法介绍&体系结构、Request和Response的功能详解
31 2
|
30天前
|
前端开发 JavaScript Java
Java与Web开发的结合:JSP与Servlet
Java与Web开发的结合:JSP与Servlet
19 0
|
30天前
|
SQL Java 数据库连接
17:数据库连接池与Servlet整合-Java Web
17:数据库连接池与Servlet整合-Java Web
42 3
|
30天前
|
缓存 前端开发 Java
15:Servlet 3.0文件上传与下载-Java Web
15:Servlet 3.0文件上传与下载-Java Web
56 5
|
30天前
|
存储 缓存 前端开发
14:Servlet中的页面跳转-Java Web
14:Servlet中的页面跳转-Java Web
51 6
|
30天前
|
安全 前端开发 Java
10:基于Servlet模拟用户登录功能的实现与解析-Java Web
10:基于Servlet模拟用户登录功能的实现与解析-Java Web
45 3
|
30天前
|
设计模式 存储 前端开发
Java从入门到精通:2.2.1学习Java Web开发,了解Servlet和JSP技术,掌握MVC设计模式
Java从入门到精通:2.2.1学习Java Web开发,了解Servlet和JSP技术,掌握MVC设计模式
|
30天前
|
前端开发 Java API
深入理解Servlet技术:Java Web开发的核心
【4月更文挑战第3天】Servlet是Java Web开发的核心技术,定义了响应客户端请求的接口。它遵循请求-响应模型,处理动态Web内容,生命周期由Web容器管理。Servlet API包含接口和类,如HttpServletRequest和HttpServletResponse,支持请求处理和会话管理。尽管现代开发常使用Spring MVC等框架,但理解Servlet对于理解框架底层机制至关重要。掌握Servlet基础知识对构建健壮的Web应用仍然必要。