The temporary upload location [/tmp/tomcat.3961673492109766761.2005/work/Tomcat/localhost/ROOT] is not valid 解决
1. 问题背景
服务运行好好的,今天访问接口突然出现问题,报错如下:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.3961673492109766761.2005/work/Tomcat/localhost/ROOT] is not valid] with root cause java.io.IOException: The temporary upload location [/tmp/tomcat.3961673492109766761.2005/work/Tomcat/localhost/ROOT] is not valid at org.apache.catalina.connector.Request.parseParts(Request.java:2821) at org.apache.catalina.connector.Request.parseParameters(Request.java:3185) at org.apache.catalina.connector.Request.getParameter(Request.java:1116) at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:84) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
2. 原因分析
A: 查看异常信息,是因为目录[/tmp/tomcat.3961673492109766761.2005/work/Tomcat/localhost/ROOT],不存在导致的。
B: 该异常为何会产生
我的应用中没有文件上传,为啥会抛org.springframework.web.multipart.MultipartException异常
首先,我们应该知道,对于http POST请求来说,它需要使用这个临时目录来存储post数据。
其次,因为该目录是挂在到/temp目录下的临时文件,那么对于一些OS系统,像centOS将经常删除这个临时目录,所有导致该目录不存在了
3. 解决方案
方案1.重启你的项目就可以了
方案2. 在application.yml文件中设置multipart location ,并重启项目
spring:
http:
multipart:
location: /data/upload_tmp
方案3. 添加启动参数 -java.tmp.dir=/path/to/application/temp/,并重启
问题的解决参考此博客: https://www.bbsmax.com/A/kvJ3wOyQJg/ 转载收藏