无法创建tempDir,将java.io.tmpdir设置为/tmp

yh2wf1be  于 2022-10-23  发布在  Java
关注(0)|答案(6)|浏览(1278)

在ubuntu服务器上运行我的springot web服务Java jar应用程序导致了下面显示的错误,我已经对该错误做了一些研究,但我无法得到解决方案。我用来运行JAR文件的命令是

java -jar mySpringBootApp.jar
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 /tmp
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at aacctt.payments.org.Application.main(Application.java:18) [classes!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to /tmp
    at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:182) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:162) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    ... 16 common frames omitted
Caused by: java.io.IOException: Read-only file system
    at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.8.0_191]
    at java.io.File.createTempFile(File.java:2024) ~[na:1.8.0_191]
    at java.io.File.createTempFile(File.java:2070) ~[na:1.8.0_191]
    at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:173) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    ... 19 common frames omitted
67up9zun

67up9zun1#

尝试以下任一操作:
1)更改/tmp的权限以授予您的用户访问权限。Chmod-R 777/tmp确保您以sudo访问权限(超级用户)运行上述命令
2)将属于的用户添加到sudo组。

pgky5nke

pgky5nke2#

对于在运行/调试配置中提供环境变量时从IntelliJ IDEA运行时获得相同异常的用户:请查看是否选中了“Include Parent Environment Variables”(包括父环境变量

eqfvzcg8

eqfvzcg83#

如果您在Kubernetes中部署Spring Boot应用程序时遇到此问题,值得检查的配置之一是readOnlyRootFilessystem。在您试图故意运行只读容器之前,必须将其设置为FALSE。
它可以在部署配置中使用,如下所示:

template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: hello-world
        securityContext:
          runAsUser: 1000
          readOnlyRootFilesystem: false ## this should not be true
42fyovps

42fyovps4#

您的应用程序用户可能没有足够的权限在/tmp目录中创建任何内容...请参阅最后一条消息Caused by: java.io.IOException: Read-only file system

px9o7tmv

px9o7tmv5#

最有可能的解释是根文件系统已满。这对我来说是个问题。

2ul0zpep

2ul0zpep6#

出现此错误的原因之一是您没有包括系统环境变量。可能您尝试使用在Java IDE中定义的不同系统变量来定义新配置,但您禁用了默认环境变量。

请启用复选框:运行/调试配置->选择您的配置->按下环境变量->选中包括系统环境变量(如上图所示)。
请记住,您需要检查是否已在系统变量中添加了临时文件的路径。

相关问题