错误:The temporary upload location [/tmp/tomcat.4424583835081790355.89/work/Tomcat/localhost/ROOT] is not valid
我使用的 spring boot 版本是1.5.7
原因:参考 https://github.com/spring-projects/spring-boot/issues/5009
意思是tomcat的临时目录会被 系统目录 tmpwatch 删除掉,甚至可能删除掉 class 文件。
解决:
1. 启动时指定新的临时目录
-Djava.io.tmpdir=/var/tmp
2. 配置文件中设置新的临时目录
server:
tomcat: basedir: /var/tmp/3. 代码中配置tomcat 临时目录
@Configurationpublic class MultipartConfig { /** * 文件上传临时路径 */ @Bean MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); String location = System.getProperty("user.dir") + "/data/tmp"; File tmpFile = new File(location); if (!tmpFile.exists()) { tmpFile.mkdirs(); } factory.setLocation(location); return factory.createMultipartConfig(); }}
参考 https://blog.csdn.net/llibin1024530411/article/details/79474953