title: Add context path to Spring Boot application
body: <p>I am trying to set a Spring Boot applications context root programmatically. The reason for the context root is we want the app to be accessed from <code>localhost:port/{app_name}</code> and have all the controller paths append to it. </p>
  
  <p>Here is the application configuration file for the web-app.</p>
  
  <pre><code>@Configuration
  public class ApplicationConfiguration {
  
    Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class);
  
    @Value("${mainstay.web.port:12378}")
    private String port;
  
    @Value("${mainstay.web.context:/mainstay}")
    private String context;
  
    private Set&lt;ErrorPage&gt; pageHandlers;
  
    @PostConstruct
    private void init(){
        pageHandlers = new HashSet&lt;ErrorPage&gt;();
        pageHandlers.add(new ErrorPage(HttpStatus.NOT_FOUND,"/notfound.html"));
        pageHandlers.add(new ErrorPage(HttpStatus.FORBIDDEN,"/forbidden.html"));
    }
  
    @Bean
    public EmbeddedServletContainerFactory servletContainer(){
        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
        logger.info("Setting custom configuration for Mainstay:");
        logger.info("Setting port to {}",port);
        logger.info("Setting context to {}",context);
        factory.setPort(Integer.valueOf(port));
        factory.setContextPath(context);
        factory.setErrorPages(pageHandlers);
        return factory;
    }
  
    public String getPort() {
        return port;
    }
  
    public void setPort(String port) {
        this.port = port;
    }
  }
  </code></pre>
  
  <p>Here is the index controller for the main page. </p>
  
  <pre><code>@Controller
  public class IndexController {
  
    Logger logger = LoggerFactory.getLogger(IndexController.class);
  
    @RequestMapping("/")
    public String index(Model model){
        logger.info("Setting index page title to Mainstay - Web");
        model.addAttribute("title","Mainstay - Web");
        return "index";
    }
  
  }
  </code></pre>
  
  <p>The new root of the application should be at <code>localhost:12378/mainstay</code>, but it is still located at <code>localhost:12378</code>. </p>
  
  <p>What am I missing that is causing Spring Boot to not append the context root before the request mapping?</p>