在项目中,一般会将文件临时保存到缓存目录

当时使用

File.createTempFile("tmp", ext,
(File) request.getServletContext().getAttribute(ServletContext.TEMPDIR))

创建临时文件时,项目一直运行正常,然而有一次报异常:

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

检查文件目录,文件确实不在,检查代码,也未发现问题。实在不知道原因,只有重启了服务器,问题也就不再出现。

今天偶然查看官方文档,发现问题所在,也提供了解决方法

If you choose to use Tomcat on CentOS be aware that, by default, a temporary directory is
used to store compiled JSPs, file uploads etc. This directory may be deleted by tmpwatch
while your application is running leading to failures. To avoid this, you may want to customize 
your tmpwatch configuration so that tomcat.* directories are not deleted, or configure
server.tomcat.basedir so that embedded Tomcat uses a different location

前往目录 /etc/cron.daily/ 中,修改 tmpwatch 文件:

#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp \
-X '/tmp/tomcat.*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done

添加一行

  -X '/tmp/tomcat.*' 10d /tmp

SpringBoot内置Tomcat缓存文件目录被意外删除导致异常的更多相关文章

  1. Spring boot内置Tomcat的临时目录被删除导致文件上传不了-问题解析

    目录 1.问题 2.1. 为什么需要使用这个/tmp/tomcat*? 2.2.那个 /tmp/tomcat* 目录为什么不存在? 三.解决办法 修改 springboot 配置,不要在/tmp 下创 ...

  2. springboot内置tomcat验证授权回调页面域名

    springboot内置tomcat验证公众号授权回调页面域名 解决方法: 网上下载一个tomcat,在server.xml文件中修改端口为springboot内置tomcat的端口号,复制验证文件到 ...

  3. SpringBoot内置tomcat启动原理

    前言          不得不说SpringBoot的开发者是在为大众程序猿谋福利,把大家都惯成了懒汉,xml不配置了,连tomcat也懒的配置了,典型的一键启动系统,那么tomcat在springb ...

  4. 去除springboot内置tomcat

    /** * @author zx * @title: ServletInitializer * @projectName activiti * @description: 解决内置tomcat * @ ...

  5. 1.springboot内置tomcat的connection相关

    最近在研究tomcat的连接超时问题,环境:jdk1.8 + springboot 2.1.1.RELEASE,以下仅为个人理解,如果异议,欢迎指正. springboot的tomcat的几个配置参数 ...

  6. springboot 内置tomcat maxPostSizs 无法设置

    ++++++++++++++++++ RT +++++++++++++++++ 如下代码方可解决: /** * tomcat配置类 * 解决post数据体大于2048kb无法接收问题 * 解决tomc ...

  7. springboot内置tomcat配置虚拟路径

    在Springboot中默认的静态资源路径有:classpath:/METAINF/resources/,classpath:/resources/,classpath:/static/,classp ...

  8. Springboot 内置tomcat 基本配置收集整理

    配置一: server:# tomcat 配置  tomcat:    # 接收队列长度    accept-count: 1000    # 最小空闲线程数    min-spare-threads ...

  9. log4j日志相对路径,Tomcat(第三方和Springboot内置)参数catalina.home和catalina.base的设置

    关于Log4j日志相对路径的配置请看:log4j 产生的日志位置设置 和 catalina.home.catalina.base . 由于我们在Log4j的配置中引入了系统属性${catalina.b ...

随机推荐

  1. 【Shiro】小读Shiro Filter

    类继承结构图 看不明白此图不要紧,后面慢慢提到此图的类: AbstractFilter,抽象过滤器 它实现Filter.继承ServletContextSupport. 它主要实现了init(Filt ...

  2. Hbase:原理和设计

    转载自:http://www.sysdb.cn/index.php/2016/01/10/hbase_principle/ ,感谢原作者. 简介 HBase —— Hadoop Database的简称 ...

  3. js date 前一天

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  4. Spark基础

    1 读取本地文件 ./spark-shell scala> val textFile=sc.textFile("file:///home/hadoop/wordfile1.txt&qu ...

  5. modelsim如何使用tcl脚本来写编译文件

    对于modelsim进行仿真,可以通过GUI来进行仿真,当然更加快速的方法可以使用TCL脚本文件进行快速仿真. Modelsim采用TCL脚本文件仿真的具体流程如下所示:      具体的操作步骤如下 ...

  6. spring JdbcTemplate数据库

    DAO package DAO; import org.springframework.jdbc.core.JdbcTemplate; public class OrderDao { private ...

  7. AES和RSA加解密的Python用法

    AES AES 是一种对称加密算法,用key对一段text加密,则用同一个key对密文解密, from Crypto import Random from Crypto.Hash import SHA ...

  8. 4e00~9fa5

    <script> function init (){ var begin = 0x4e00; var end = 0x9fa5; var str = ''; for(var a=begin ...

  9. ES6 扩展运算符 三点(...)

    含义 扩展运算符( spread )是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[, , ]) // 1 2 3 conso ...

  10. Axure RP 9 Beta 开放下载(更新激活密钥和汉化包)

    2018年9月9号,7月9号来厦门入职,已经两个月了.这两个月的生活状态真心不好,一方面工作很忙(刚工作是这样?),虽然工资还可以,但总感觉性价比很低,自已对这份工作不够热爱也许.另一方面,来到新城市 ...