U2647's blog 一个热爱学习的 Java 程序员,喜欢 Vue,喜欢深度学习 Dubbo Flutter SpringBoot Debug Notes Java LeetCode Python Redis Android DesignPattern mdi-home-outline 首页 mdi-cloud-outline 标签云 mdi-timeline-text-outline 时间轴 mdi-draw-pen 文章总数 62
Spring Boot 上传文件路径错误解决 the temporary upload location xxx is not valid Spring Boot 文件上传 the temporary upload location mdi-cursor-default-click-outline 点击量 62

问题

正常运行一个多月的项目今天上传文件的时候突然出了个下面的异常:

org.springframework.web.multipart.MultipartException: Could not parse 
multipart servlet request; nested exception is java.io.IOException: The 
temporary upload location [/tmp/xxxx/work/Tomcat/localhost/ROOT] is not valid

原因

检查发现服务器上的 /tmp文件夹确实是空的,网上查了一下原因:说是 tmp目录会被系统自动清理。所以才导致找不到路径的问题。

Debug

解决方法有三种:

  1. 重启应用

临时性的的解决方法是重启下应用就可以了,不过问题是,后期还会出现这个问题,指标不治之本。

  1. 修改启动器:

在启动类里注入一个Bean:

@Bean

MultipartConfig() {

    MultipartConfigFactory factory =new MultipartConfigFactory(); 

    factory.setLocation("/xxx/xxx"); 

    return factory.createMultipartConfig();

}
  1. 修改配置文件:

也可以修改配置文件。添加下面的配置:

server:
  tomcat:
    basedir: /xxx/xxx
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
我的GitHub 我的LeetCode 我的掘金
Powered by Hexo Powered by three-cards
Copyright © 2017 - {{ new Date().getFullYear() }} 某ICP备xxxxxxxx号