-
springboot /tmp 临时目录的具体实现
springboot应用服务再启动的时候,会在操作系统的/tmp目录,本文主要介绍了springboot /tmp 临时目录的具体实现,具有一定的参考价值,感兴趣的可以了解一下
1.生成机制
在linux系统中,springboot应用服务再启动(java -jar 命令启动服务)的时候,会在操作系统的/tmp目录下生成一个tomcat*的文件目录,上传的文件先要转换成临时文件保存在这个文件夹下面。
因为流取一次消费之后,后面无法再从流中获取数据,所以缓存方便后续复用;
2.产生异常
上线后可能tomcat临时文件夹会被Linux删除,会报找不到错误,现在赶紧记录一下,已被不时之需
cat /usr/lib/tmpfiles.d/tmp.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# See tmpfiles.d(5) for details
# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d
# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp
3.解决办法
3.1 重启大法
既然目录被删除了,重启一下服务,让系统重新生成该目录,临时解决(但是以后目录还可能被删除)
3.1 从Linux层面修改 /tmp目录的清理策略
配置一下不删除tmp目录下的tomcat
vim /usr/lib/tmpfiles.d/tmp.conf
# 添加下面一行
x /tmp/tomcat.*
# 重启服务
systemctl restart systemd-tmpfiles-clean
3.2 增加JVM配置
#定临时目录为/app/xxx/tmp
-Djava.io.tmpdir=/app/xxx/tmp(自定义路径)
3.3 增加JVM配置
-java.tmp.dir=/data/upload_tmp
3.4 添加spring boot配置
spring:
http:
multipart:
location: /data/upload_tmp
3.5 使用配置类配置
在Spring容器中注册MultipartConfigElement对象,通过MultipartConfigFactory指定路径,路径不存在的话就创建
@Bean
public 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();
}
到此这篇关于springboot /tmp 临时目录的具体实现的文章就介绍到这了,更多相关springboot /tmp 临时目录内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持
原文链接:https://blog.csdn.net/qq_37924396/article/details/136301474
最新更新
Java中使用标签(label)来控制循环的执行流
springboot /tmp 临时目录的具体实现
SpringBoot高并发下控制限流的几种实现方法
mybatis insert 返回自增主键的实现示例
SpringBoot实现发送验证码功能(图片验证码
springboot中redis操作Hash踩坑解决
详解如何有效地处理Java中的多线程
Mybatis的Cursor避免OOM异常的方法详解
Java服务如何调用系统指令、Bat脚本记录
SpringBoot 下在 yml 中的 logging 日志配置
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比