zoukankan      html  css  js  c++  java
  • SpringBoot项目的The temporary upload location ***is not valid 问题

    springboot项目,部署到服务器后,运行一段时间后,处理一些文件上传的接口时,后报异常。

    Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.7333297176951596407.9000/work/Tomcat/localhost/ROOT] is not valid。

    查阅资料后,发现是centos对'/tmp'下文件自动清理的原因。

    在springboot项目启动后,系统会在‘/tmp’目录下自动的创建几个目录(我的项目是以下的文件夹):

           1, hsperfdata_root,

            2,tomcat.************.8080,(结尾是项目的端后)

           3,tomcat-docbase.*********.8080。

    Multipart(form-data)的方式处理请求时,默认就是在第二个目录下创建临时文件的。
      这篇文章对自动清理文件有很好的说明http://blog.51cto.com/kusorz/2051877?utm_source=oschina-app。

    处理方式:改变临时文件的存储路径。如下:

    @Configuration
    public 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();
        }
    }

  • 相关阅读:
    spring boot整合使用mybatis
    spring boot整合使用jdbcTemplate
    spring boot全局捕获异常
    springboot 静态资源访问
    spring boot项目的启动方式
    第一个spring boot项目 springboot-helloworld
    ASP.Net MVC 登录授权验证
    C# mysql 事务处理
    无法删除数据库,因为该数据库当前正在使用"问题解决
    mysql 按照小时去除一段时间内的不同状态数据统计
  • 原文地址:https://www.cnblogs.com/zhuyeshen/p/12677758.html
Copyright © 2011-2022 走看看