SpringBoot内置Tomcat缓存文件目录被意外删除导致异常
在项目中,一般会将文件临时保存到缓存目录
当时使用
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缓存文件目录被意外删除导致异常的更多相关文章
- Spring boot内置Tomcat的临时目录被删除导致文件上传不了-问题解析
目录 1.问题 2.1. 为什么需要使用这个/tmp/tomcat*? 2.2.那个 /tmp/tomcat* 目录为什么不存在? 三.解决办法 修改 springboot 配置,不要在/tmp 下创 ...
- springboot内置tomcat验证授权回调页面域名
springboot内置tomcat验证公众号授权回调页面域名 解决方法: 网上下载一个tomcat,在server.xml文件中修改端口为springboot内置tomcat的端口号,复制验证文件到 ...
- SpringBoot内置tomcat启动原理
前言 不得不说SpringBoot的开发者是在为大众程序猿谋福利,把大家都惯成了懒汉,xml不配置了,连tomcat也懒的配置了,典型的一键启动系统,那么tomcat在springb ...
- 去除springboot内置tomcat
/** * @author zx * @title: ServletInitializer * @projectName activiti * @description: 解决内置tomcat * @ ...
- 1.springboot内置tomcat的connection相关
最近在研究tomcat的连接超时问题,环境:jdk1.8 + springboot 2.1.1.RELEASE,以下仅为个人理解,如果异议,欢迎指正. springboot的tomcat的几个配置参数 ...
- springboot 内置tomcat maxPostSizs 无法设置
++++++++++++++++++ RT +++++++++++++++++ 如下代码方可解决: /** * tomcat配置类 * 解决post数据体大于2048kb无法接收问题 * 解决tomc ...
- springboot内置tomcat配置虚拟路径
在Springboot中默认的静态资源路径有:classpath:/METAINF/resources/,classpath:/resources/,classpath:/static/,classp ...
- Springboot 内置tomcat 基本配置收集整理
配置一: server:# tomcat 配置 tomcat: # 接收队列长度 accept-count: 1000 # 最小空闲线程数 min-spare-threads ...
- log4j日志相对路径,Tomcat(第三方和Springboot内置)参数catalina.home和catalina.base的设置
关于Log4j日志相对路径的配置请看:log4j 产生的日志位置设置 和 catalina.home.catalina.base . 由于我们在Log4j的配置中引入了系统属性${catalina.b ...
随机推荐
- SQL Server 2016新特性:Live Query Statistics
SSMS可以提供可以查看正在执行的计划.live query plan可以查看一个查询的执行过程,从一个查询计划操作到另外一个查询计划操作.live query plan提供了整体的查询运行进度和操作 ...
- css实现高度或者宽度不固定的div元素垂直左右居中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 进一步聊聊weight initialization
深度学习模型训练的过程本质是对weight(即参数W)进行更新,这需要每个参数有相应的初始值. 有人可能会说:"参数初始化有什么难点?直接将所有weight初始化为0或者初始化为随机数!&q ...
- FastDFS常用命令
1.启动FastDFS tracker: /usr/local/bin/fdfs_trackered %FastDFS%/tracker.conf storage: /usr/local/bin/fd ...
- 为什么要使用NoSQL
转载自:http://www.infoq.com/cn/news/2011/01/nosql-why [编者按]NoSQL在2010年风生水起,大大小小的Web站点在追求高性能高可靠性方面,不由自主都 ...
- Netty WebSocket 开发
代码: Server package netty.protocol.websocket.server; import io.netty.bootstrap.ServerBootstrap; impor ...
- java interface接口的传值方法
A 类 package interface_test; public class A { private IPresenter ip; public A(IPresenter ip) { this.i ...
- Transaction rolled back because it has been marked as rollback-only分析解决方法
1. Transaction rolled back because it has been marked as rollback-only事务已回滚,因为它被标记成了只回滚<prop key= ...
- 【转】Yelp是如何实现每天运行数百万个测试的
Yelp每天要运行数百万个测试,确保开发人员提交的代码不会对已有的功能造成破坏.如此巨大规模的测试,他们是怎么做到的呢?以下内容翻译自 Yelp 的技术博客,并已获得翻译授权,查看原文 How Yel ...
- vscode c++ 编译生成后,调试时无法命中断点
//test.cpp #include <stdio.h> ; void print_line(char *str) { if (str != NULL) printf("%s\ ...