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

异常信息:
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1428942566812653608.8090/work/Tomcat/localhost/ROOT] is not valid
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:122)
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:113)
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest.java:86)
  at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:93)
  at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1128)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:960)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

分析原因

1.该异常是如何产生的

当我发送一个post请求,导致该异常了

从上面的异常信息来看,是因为该目录[/tmp/tomcat.1428942566812653608.8090/work/Tomcat/localhost/ROOT],不存在导致的。

 

2.该异常为何会产生
我的应用中没有文件上传,为啥会抛org.springframework.web.multipart.MultipartException异常
2.1)首先,我们应该知道,
对于http POST请求来说,它需要使用这个临时目录来存储post数据。
2.2)其次,因为该目录是挂在到/temp目录下的临时文件,那么对于一些OS系统,像centOS将经常删除这个临时目录,所有导致该目录不存在了

我用的是阿里云的服务器

 

解决方案

方案1.重启你的服务器(springboot),最简便方法

方案2.在application.yml文件中设置multipart location ,然后重启你的服务器

spring:
  http:
    multipart:
      location: /data/upload_tmp

 

你可能感兴趣的:(Java,Springboot,上传多文件报异常)