How to Change Spring Boot Context Path

By Yashwant Chavan, Views 92, Last updated on 15-Apr-2019

By default Spring Boot application accessed via root context path ("/") like http://localhost:port/. But in real world application development, you have to specify the context path http://localhost:port/{app_name}.

In this tutorial, we will learn the different ways to configure root context.

tags spring spring-boot

You can change Spring Boot application context root using "/src/main/resources/" file. Just define the property server.servlet.context-path along with context root value.


Java System Property

We can set the context path using a Java system property System.setProperty("server.servlet.context-path", "/technicalkeeda");.


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

public class Application {
	public static void main(String[] args) {
		System.setProperty("server.servlet.context-path", "/technicalkeeda");, args);

OS Environment Variable

Define enviornment variable SERVER_SERVLET_CONTEXT_PATH with context path value.


Command Line Arguments

We can set the properties using command line arguments also.

java -jar SpringBoot-1.0.jar --server.servlet.context-path=/technicalkeeda

Tomcat started with specified context path

2019-04-13 12:34:47.643  INFO 1448 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-04-13 12:34:47.715  INFO 1448 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/technicalkeeda'
2019-04-13 12:34:47.723  INFO 1448 --- [           main]       : Started Application in 4.245 seconds (JVM running for 4.956)


Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]