samadadi
samadadi

Reputation: 3370

How to Get Spring Boot Application Root Path?

Spring Boot Applications Use Embedded Tomcat/Jetty So How to Get Spring Boot Application Root Path?

Upvotes: 3

Views: 10801

Answers (1)

samadadi
samadadi

Reputation: 3370

In Spring MVC applications we deploy our application to external tomcat contianer so we can use HttpServletRequest class to find root folder path.

But in Spring Boot application using with HttpServletRequest does not return application root folder path. Spring Boot application is java application with main method.

So I use this Workaround. If you find any better way, share with me. thanks.

YourClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();

CodeSource.getLocation() Returns the URL location associated with code source.

URL.getPath() Gets the path part of URL.

Upvotes: 1

Related Questions