Springboot 内置Tomcat导致文件上传失败

Spring boot内置Tomcat的临时目录被删除导致文件无法上传

[io-11510-exec-3] com.seven.GlobalDefultExceptionHandler   : Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.3614207742003090802.11510/work/Tomcat/localhost/ROOT] is not valid

org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.3614207742003090802.11510/work/Tomcat/localhost/ROOT] is not valid
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:122) ~[spring-web-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:113) ~[spring-web-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:86) ~[spring-web-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
    at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:93) ~[spring-web-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]

解决方案:

1.应用重启

2.增加服务配置,自定义baseDir

server.tomcat.basedir=/tmp/tomcat

3.配置不删除tmp目录下的Tomcat 

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

#添加一行

x /tmp/tomcat.*

 

posted @ 2021-02-23 17:37  我的博客我的人生  阅读(510)  评论(0编辑  收藏  举报