springboot开发,部署服务器,遇到以下报错:
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.2090842327674075737.8081/work/Tomcat/localhost/ROOT] is not valid at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:120) ~ [spring-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
解决:
在application.yml或application.properties中添加如下配置:
server:
port: 5555
servlet:
context-path: /xxxx
#这段配置
tomcat:
remote-ip-header: x-forward-for
uri-encoding: UTF-8
max-threads: 1000
max-http-header-size: 8096
#核心代码,设置tomcat的basedir
basedir: ${user.home}/tomcat/tmp
关于basedir,源码是这么解释的,Tomcat base directory. If not specified, a temporary directory is used.
,也就是tomcat基础目录,如果没有指定,就用临时目录
。
加上这段tomcat的配置,到目前为止,在未出现这个错误。
方法来源:https://blog.csdn.net/moshowgame/article/details/82622546