原因:当使用MultipartFile做上传操作时,
1:spring是先将上传文件存放在一个临时地址,默认/tmp目录下
2:进入controller进行业务操作
linux环境中/tmp目录是存放临时文件的,当这个目录下的子目录10天之内,没有使用过,linux就会将目录删掉,然后上传文件时就会在第一步发生异常(我遇到就是这种问题)
2020-02-10 10:17:51.058 [6fa786300462c02fadfe427e24c4f79e] ERROR [http-nio-9345-exec-10] com.weihui.merchant.wallet.web.aop.ExceptionAdvice :Global error:{}
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. /tmp/cavale/upload_08517793_352f_4bf6_b5ad_15ceeee0e0a9_00000033.tmp (No such file or directory)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:165) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:142) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1067) ~[spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE]
修改方式:第一种方式:将linux下的存放应用的临时文件的那个子目录,非/tmp目录,设置为不删除 tmpwatch命令
第二种方式:设置MultipartConfig的location,将临时文件的存放地址,改为非/tmp目录