Spring Boot – How to change Context Path

In Spring Boot, to change the context path, update server.contextPath properties. The following examples update the context path from / to /mkyong or http://localhost:8080/mkyong

By default, the context path is “/”.

P.S Tested with Spring Boot 1.4.2.RELEASE

1. Properties & Yaml

1.1 Update via a properties file.



1.2 Update via a yaml file.


  port: 8080
  contextPath: /mkyong

2. EmbeddedServletContainerCustomizer

Update via code, this overrides properties and yaml settings.


package com.mkyong;

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;

public class CustomContainer implements EmbeddedServletContainerCustomizer {

	public void customize(ConfigurableEmbeddedServletContainer container) {




3. Command Line

Update the context path by passing the system properties directly.


java -jar -Dserver.contextPath=/mkyong spring-boot-example-1.0.jar


  1. Spring Boot – Embedded servlet containers
  2. Spring Boot – Externalized Configuration
  3. Spring Boot – How to change Tomcat port

About the Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.


6 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
6 Comment authors
keshav guptaGabriel AndradePankaj ShindeShahid AkhtarSanthosh Rongala Recent comment authors
newest oldest most voted
Shahid Akhtar
Shahid Akhtar

Hi Mkyong, EmbeddedServletContainerCustomizer is used to make changes in embedded tomcat and it does not work with standalone tomcat. I tried to change contextPath in both using application.properties file as well as using above mentioned code snippet but it does not work with standalone tomcat. Would you please let me know what changes i have to make so that contextPath can be set for standalone via application.properties or some otherway? Thanks, Shahid Akhtar.


How to change Spring Security related configuration according to the new Context Path.

Gabriel Andrade
Gabriel Andrade

Can you help me find out how to change the context path on a spring boot application running on external tomcat?
Seems that application.properties is being ignored.
One other thing is that I cant deploy more than one WAR in the same tomcat, it gives me the following error:

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource
(HikariPool-2)] with key ‘dataSource’; nested exception is javax.management.InstanceAlreadyExistsException:

Thanks in advance.

Santhosh Rongala
Santhosh Rongala

how to added jndi URL in Spring Boot? i want configure ehcahe.xml file in tomcat ? but using spring boot where i have to configure ? could you please help me on that? i have some properties files out side the application how to load those files?

Pankaj Shinde
Pankaj Shinde

Hi, In spring boot web application, the user is allowed to upload the profile picture. This file gets saved in /resource/user-images folder. When user opens the profile page, the image is shown using the url http://servername:8080/myapp/resource/user-images/.png. This functionality works fine when I am launching application from IDE. I deployed the .war file on Ubuntu linux – I am starting the spring boot application using the embedded tomcat. This functionality stopped working. The image files are getting saved in the folder where .war file is kept but the images are not accessible using the URL – http://servername:8080/myapp/resource/user-images/.png. How to set the… Read more »

keshav gupta
keshav gupta

how to know the existing URL in existing Spring -boot application?
like in the old WebLogic world we could open the WebLogic console and find it…