Spring Boot with Servlet Context Path – Example

You just want to see an minimal example how to change servlet context path and port in  Spring boot.

This page is for you.

This example is a part of  Spring Boot with all examples

Full Code with Spring Boot 1.5.8.RELEASE:


What you need for run this:

  • Maven 3
  • Java 8

What the code will do:

  • Let you change url to http://localhost:<customPort>/<servletContext>


This is the file structure:

From this example Spring Boot with Basic REST , you can call Spring Boot with this url:

You may think:

  • How can I change the port , for example from 8080 to 8081
  • How can I add the servlet context path , for example from / to /test

You just have to add application.properties, like this:


run this in console:

Then run this to start:

You should see something like this:

Open a browswer and try to go to this url: