Add Context Path To Spring Boot Application
Answer : Why are you trying to roll your own solution. Spring-boot already supports that. If you don't already have one, add an application.properties file to src\main\resources . In that properties file, add 2 properties: server.contextPath=/mainstay server.port=12378 UPDATE (Spring Boot 2.0) As of Spring Boot 2.0 (due to the support of both Spring MVC and Spring WebFlux) the contextPath has been changed to the following: server.servlet.contextPath=/mainstay You can then remove your configuration for the custom servlet container. If you need to do some post processing on the container you can add a EmbeddedServletContainerCustomizer implementation to your configuration (for instance to add the error pages). Basically the properties inside the application.properties serve as a default you can always override them by using another application.properties next to the artifact you deliver or by adding JVM parameters ( -Dserver.port=6666 ). See also The Reference...