在springboot启动的时候遇到一个问题,在本地启动完全没有问题,但是放到服务器上启动时,则出现下面的问题:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.xxx.8120] to use as the base directory
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.example.ruledemo.RuledemoApplication.main(RuledemoApplication.java:10) [ruledemo.jar:na]
Caused by: java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.3736867899040188915.8080] to use as the base directory
at org.apache.catalina.startup.Tomcat.initBaseDir(Tomcat.java:724) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.startup.Tomcat.getServer(Tomcat.java:539) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.startup.Tomcat.getService(Tomcat.java:472) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:165) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 8 common frames omitted
意思就是无法启动服务,没办法创建目录?权限不够?这必然不可能,使用的已经是最高权限。那必然便是磁盘不够了,df -h
一查果然如此。理论上该问题到这里就结束了啊,但是问题是这目录里的东西不知道哪些没有用哪些有用啊?那这怎么办?
没事,假若别的地方还有空间,那么一开始其实系统已经提示你了:
Try using the -Djava.io.tmpdir= option to select an alternate temp location.
照着方法来就是了,所以我们在启动jar包的时候,多加上这么一条,形如:
java -Djava.io.tmpdir=/xxx/xxxx/tmp -jar xxxx.jar
中间的tmpdir替换成有空间的目录就行了,最后项目完美的启动了启动。
Started Application in 17.586 seconds (JVM running for 15.268)