Unable to create tempDir. java.io.tmpdir is set to C:\Users\SRV-DA~1\AppData\Local\Temp\5\

Unable to create tempDir. java.io.tmpdir is set to C:\Users\SRV-DA~1\AppData\Local\Temp\5\

1.问题描述

在Windows server下,跑了几个月的程序,突然报警了,我也很无语

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to C:\Users\SRV-DA~1\AppData\Local\Temp\5\
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:576) ~[spring-context-5.3.4.jar!/:5.3.4]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) [spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.4.3.jar!/:2.4.3]
        at com.delta.DmsReplaceSapFileApplication.main(DmsReplaceSapFileApplication.java:13) [classes!/:0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [dms-replace-sap-file-0.1-SNAPSHOT.jar:0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) [dms-replace-sap-file-0.1-SNAPSHOT.jar:0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [dms-replace-sap-file-0.1-SNAPSHOT.jar:0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [dms-replace-sap-file-0.1-SNAPSHOT.jar:0.1-SNAPSHOT]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to C:\Users\SRV-DA~1\AppData\Local\Temp\5\
        at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:195) ~[spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:186) ~[spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.4.3.jar!/:2.4.3]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159) ~[spring-boot-2.4.3.jar!/:2.4.3]
        ... 17 common frames omitted
Caused by: java.nio.file.NoSuchFileException: C:\Users\SRV-DA~1\AppData\Local\Temp\5\tomcat.8082.2026523687593087531
        at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsFileSystemProvider.createDirectory(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.Files.createDirectory(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.TempFileHelper.create(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.TempFileHelper.createTempDirectory(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.Files.createTempDirectory(Unknown Source) ~[na:1.8.0_191]
        at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:189) ~[spring-boot-2.4.3.jar!/:2.4.3]
        ... 20 common frames omitted
  • 报警Unable to create tempDir. java.io.tmpdir is set to C:\Users\SRV-DA~1\AppData\Local\Temp\5\
  • SRV-DA~1为什么变成这样,我也不知道(就是当前用户名SRV-Data)
  • 报警的意思就是临时路径找不到\temp\5\

2.解决方法

  • 在C盘找到对应位置。手动添加路径(不推荐)
  • 指定一个路径,如下
@Configuration(proxyBeanMethods = false)
public class MultipartConfig {
    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // C:/Users/xxx/AppData/Local/Temp
        String location = System.getProperty("user.home") + "/AppData/Local/Temp";
        File tmpFile = new File(location);
        if (!tmpFile.exists()) {
            tmpFile.mkdirs();
        }
        factory.setLocation(location);
        return factory.createMultipartConfig();
    }
}
  • 重新指定java -Djava.io.tempdir=D:/tmpdir -jar xxxx.jar
  • 修改tomcat临时存放文件位置(不推荐)
//此方法会将所有tomcat的临时文件都放在指定目录,新目录没有定时清理功能,不建议
server.tomcat.basedir=xxxxxx
  • 修改VM定时清理功能(不建议)

3.好奇

查看了一下,用户名下面确实好多临时文件夹

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百世经纶『一页書』

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值