title: Spring MVC - run application in absolute path
body: <p>I have a demo application of Spring MVC - I just follow udemy course for it.</p>
  <p>I have created the first controller and view. All is working fine, however I have one doubt about.
  The pom file of application contains:</p>
  <pre><code>  &lt;groupId&gt;eu.smartgroup&lt;/groupId&gt;
    &lt;artifactId&gt;spring-demo-mvc&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
  </code></pre>
  <p>So when I run application on tomcat server it starts, but it is available with url: http://localhost:8080/spring_demo_mvc_war</p>
  <p>Is there possibility to configure application so it will be available in the root path: http://localhost:8080/ (without project name after slash)?</p>
  <p><strong>Edit:</strong>
  Here is full application.yml</p>
  <pre><code>server:
    servlet:
      contextPath: /
  </code></pre>
  <p>HelloController.java</p>
  <pre><code>package eu.test.springdemo.mvc;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.*;
  
  @Controller
  @RequestMapping(&quot;/&quot;)
  public class HelloController {
  
      @GetMapping(&quot;/&quot;)
      public String showPage() {
          return &quot;main-menu&quot;;
      }
  }
  </code></pre>
  <p>DemoAppConfig.java</p>
  <pre><code>package eu.test.springdemo.config;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.ViewResolver;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages=&quot;eu.test.springdemo&quot;)
  public class DemoAppConfig implements WebMvcConfigurer {
  
      // define a bean for ViewResolver
  
      @Bean
      public ViewResolver viewResolver() {
  
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  
          viewResolver.setPrefix(&quot;/WEB-INF/view/&quot;);
          viewResolver.setSuffix(&quot;.jsp&quot;);
  
          return viewResolver;
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler(&quot;/resources/**&quot;).addResourceLocations(&quot;/resources/&quot;);
      }
  }
  </code></pre>