Spring Boot Change Context Path

In this article, we will look in to the options to change context path in Spring Boot application. By default, Spring Boot server the context from the root ("/"). Let’s look at some options to change the context path in Spring Boot.


1. Change Context Path using Properties file

The application.properties file provides many configurations including the option to change the application context for your application. To change the context path use the following properties in the application.properties file:

Spring Boot 1.0
#### Spring Boot 2.0 Configurations ####


2. Using Java System Property

Second alternate is to use the Java system property to set the context path for your Spring Boot application.



3. Command Line Arguments

Spring Boot also provides an option to pass the context information as part of the command line arguments.

$ java -jar javadevjournal.jar --server.servlet.context-path=/javadevjournal


4. Using Java Configurations

Spring Boot 1.0 and 2.0 provides a different way to configure the context using Java configurations.With Spring Boot 2, we can use WebServerFactoryCustomizer.

public class AppCustomizer implements WebServerFactoryCustomizer {

    public void customize(ConfigurableServletWebServerFactory factory) {

For Spring Boot 1.0, we can create an instance of EmbeddedServletContainerCustomizer:

public class AppContainerCustomizer implements EmbeddedServletContainerCustomizer {
    public void customize(ConfigurableEmbeddedServletContainer container) {




In this article, we saw a different way to change context path in Spring Boot application.The source code for this post is available over GitHub.

0 0 vote
Article Rating

Java Development Journal

Hello!! Welcome to the Java Development Journal. We love to share our knowledge with our readers and love to build a thriving community.

follow me on:
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x