title: WebApplicationInitializer not working after upgrading spring-boot-starter-parent
body: <p>My code used to works well before I upgraded spring-boot-starter-parent from <em>1.0.2.RELEASE</em> to <em>2.1.0.RELEASE</em>.</p>
  
  <p>When the version of spring-boot-starter-parent is <em>1.0.2.RELEASE</em>, I could deploy this project to tomcat, run tomcat, and when I type localhost:8080/greeting.html on my browser I could see 'Hello World".</p>
  
  <p>But after I upgrade the version to <em>2.1.0.RELEASE</em> and do the same thing, I just got a <em>404 not found</em> error.</p>
  
  <p><strong>QUESTION</strong>: How can I fix this problem with version <em>2.1.0.RELEASE</em> of spring-boot-starter-parent?</p>
  
  <p>Here is my code snippet and the pom file:</p>
  
  <p>pom.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.pluralsight&lt;/groupId&gt;
      &lt;artifactId&gt;event-tracker&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;event-tracker&lt;/name&gt;
      &lt;description&gt;An app to track our Events&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.0.RELEASE&lt;/version&gt;
          &lt;!--&lt;version&gt;1.0.2.RELEASE&lt;/version&gt;--&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>WebConfig:</p>
  
  <pre><code>package com.pluralsight;
  
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.pluralsight")
  public class WebConfig {
  }
  </code></pre>
  
  <p>WebAppInitializer:</p>
  
  <pre><code>package com.pluralsight;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletRegistration;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.ContextLoaderListener;
  import org.springframework.web.context.WebApplicationContext;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  public class WebAppInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext servletContext) {
          WebApplicationContext context = getContext();
          servletContext.addListener(new ContextLoaderListener(context));
          ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("*.html");
      }
  
      private AnnotationConfigWebApplicationContext getContext() {
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.setConfigLocation("com.pluralsight.WebConfig");
          return context;
      }
  }
  </code></pre>
  
  <p>HelloController:</p>
  
  <pre><code>package com.pluralsight.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  @Controller
  public class HelloController {
  
      @RequestMapping(value = "/greeting")
      public String sayHello(Model model) {
          model.addAttribute("greeting", "Hello World");
  
          return "hello.jsp";
      }
  }
  </code></pre>