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

当时使用

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

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

SpringCloud(12)—— SpringBoot内置Tomcat缓存文件目录意外删除导致异常

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

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

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

SpringCloud(12)—— SpringBoot内置Tomcat缓存文件目录意外删除导致异常

明显增加了 -X '/tmp/tomcat.*' 240 /tmp

或者

SpringCloud(12)—— SpringBoot内置Tomcat缓存文件目录意外删除导致异常

明显增加了 -X '/tmp/tomcat.*' 10d /tmp

问题就应该得到了解决。

但是解决这个问题之前,我重启了服务器,就好了,希望这种解决方案是有效的。

 

相关文章:

  • 2022-02-07
  • 2021-11-18
  • 2021-08-24
  • 2021-11-23
  • 2021-06-24
  • 2021-10-31
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-06-10
  • 2021-06-30
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案