Failed to parse multipart servlet request; nested exception is java.io.IOException

今天遇到一个奇怪的问题,上传文件一直都 没出现问题,今天居然出现问题了,查看日至,报如下错误:

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.2018743807255784134.8008/work/Tomcat/localhost/zc]

根据错误提示,马上去tmp目录下查看对应文件是否存在,发现连tomcat目录都不存在了

原来是因为cenos7系统会清理tmp文件夹,我们可以进入这个文件查看tmp的清理规则

/usr/lib/tmpfiles.d/tmp.conf

# Clear tmp directories separately, to make them easier to override

v /tmp 1777 root root 10d

v /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes

x /tmp/systemd-private-%b-*

X /tmp/systemd-private-%b-*/tmp

x /var/tmp/systemd-private-%b-*

X /var/tmp/systemd-private-%b-*/tmp

从上面的代码可以看出,他会自动清理10天前/tmp下的目录,清理30天前/var/tmp下的目录

而下面的代码则是排除,因此方案有两个

1,在上面的文件中加入我们tomcat的排除规则

x /tmp/tomcat.*

2,在我们的jar包后面加入临时目录

-Djava.io.tmpdir=/opt/projecttmp


爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情Blog Img