Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2020-10-08 23:35:36.770 ERROR 10216 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is **java.lang.IllegalArgumentException: The location [C:\Temp\tomcat.2991047597755146144.9000] specified for the base directory is not a directory**
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at info.inetsolv.CloudConfigServerSbApplication.main(CloudConfigServerSbApplication.java:13) [classes/:na]
Caused by: java.lang.IllegalArgumentException: The location [C:\Temp\tomcat.2991047597755146144.9000] specified for the base directory is not a directory
    at org.apache.catalina.startup.Tomcat.initBaseDir(Tomcat.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.startup.Tomcat.getServer(Tomcat.java:657) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.startup.Tomcat.getService(Tomcat.java:589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:182) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    ... 9 common frames omitted

Comment From: wilkinsona

Does C:\Temp exist on your machine and does the user running your application have permission to create a sub-directory in that location?

Comment From: rulerskbr99

Does C:\Temp exist on your machine and does the user running your application have permission to create a sub-directory in that location?

Yes i have c:\Temp directory and only 1 user exist (i.e Admin)

Comment From: wilkinsona

Thanks. Unfortunately, I cannot explain the failure in that case. The code that creates the directory is the following:

https://github.com/spring-projects/spring-boot/blob/a099cd9420a23ffc9ffea957d54667d854aa550d/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java#L186-L198

We aren't checking the return value of delete() or mkdir() so I had wondered if one of those calls was failing. However, looking more closely, File.createTempFile would have failed in that case and thrown an IOException.

I believe the problem you are seeing is specific to your environment as we haven't had a report from anyone else or seen this failure on our Windows CI. Perhaps you have a virus scanner that scans the newly created file and prevents it from being deleted?

Regardless, I think we could improve the diagnostics here while also simplifying the code by switching to java.nio.file.Files.createTempDirectory(String, FileAttribute<?>...). We can use this issue to do that.

Comment From: kaushikrk

is there any workaround for this issue? I also face this issue.

Comment From: wilkinsona

@kaushikrk You can set server.tomcat.basedir to a location of your choosing to avoid the creation of the temporary directory.

Comment From: rulerskbr99

Do i need to set any environment variable for this issue like TEMP folder....?

Comment From: wilkinsona

The location of temporary files is determined by the java.io.tmpdir system property. This answer on Stack Overflow has some useful information on the system property's default value on Windows and the environment variables that affect it.