In Spring Boot, you can change the context path of your application by setting the server.servlet.context-path property in the or application.yml file.

Using Application Properties file:

For example, if you want to set the context path to /myapp, you would add the following line to the file:


Using Application Properties file: application.yml

        context-path: /myapp

Change context path programmatically:

public class ServletConfig {

       String contextPath;

     public ServletWebServerFactory servletContainer() {
         TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
         return tomcat;


Change context path using command line arguments

for example --server.servlet.context-path=/myapp

java -jar my-app.jar --server.servlet.context-path=/myapp --server.port=8585

It is important to notice that the context path should start with a forward slash (“/”) and should not end with a forward slash, otherwise it will not work as expected.