title: Deploying Spring 5.x on Tomcat 10.x
body: <p>TL;DR: I have a Spring MVC <em><a href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program" rel="noreferrer">Hello, World!</a></em> application that works on Tomcat 9. The same application on Tomcat 10 gives a 404 error for web request mappings.</p>
  <p><strong>The Problem</strong></p>
  <p>When deploying a Spring MVC 5 <em>Hello, World!</em> application to Tomcat 10, the application gives a 404 error for web request mappings. The same <em>Hello, World!</em> application works on Tomcat 9. It displays the <em>Hello, World!</em> message on Tomcat 9.</p>
  <p><strong>What I Expected</strong></p>
  <p>I expected the application to display the <em>Hello, World!</em> message on Tomcat 10.</p>
  <p><strong>Environment</strong></p>
  <ul>
  <li>MS Windows 10</li>
  <li>Tomcat 10.0.2</li>
  <li>Spring MVC 5.3.3</li>
  </ul>
  <p><strong>Research I Performed</strong></p>
  <p>I researched in the Spring Reference Manual, Section on Web Servlet. I also tested Spring MVC Tutorials online. These tutorials worked on Tomcat 9. However, the same tutorials failed on Tomcat 10. I also performed Google search on Tomcat 10. I saw references to Jakarta EE, but I am not sure if this is the source of the issue. Java EE 8 and Jakarta EE 8 are backwards compatible.</p>
  <p><strong>How to Reproduce</strong></p>
  <p>I created a very basic <em>Hello, World!</em> project to test this out. Here is the code that I'm using for the project.</p>
  <h3>File <em>pom.xml</em></h3>
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.example.spring&lt;/groupId&gt;
      &lt;artifactId&gt;example-spring&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
          &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;5.3.3&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;4.0.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3.1&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <h3>File <em>ProjectInitializer.java</em></h3>
  <pre><code>package com.example;
  
  import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  
  public class ProjectInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[] { PureJavaConfig.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { &quot;/&quot; };
      }
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return null;
      }
  }
  </code></pre>
  <h3>File <em>PureJavaConfig.java</em></h3>
  <pre><code>package com.example;
  
  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.view.InternalResourceViewResolver;
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(&quot;com.example&quot;)
  public class PureJavaConfig {
  
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setSuffix(&quot;.jsp&quot;);
          resolver.setPrefix(&quot;/WEB-INF/jsp/&quot;);
          return resolver;
      }
  
  }
  </code></pre>
  <h3>File <em>TutorialController.java</em></h3>
  <pre><code>package com.example;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.GetMapping;
  
  @Controller
  public class TutorialController {
  
      @GetMapping(&quot;/&quot;)
      public String home() {
          return &quot;home&quot;;
      }
  }
  </code></pre>
  <h3>File <em>home.jsp</em></h3>
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;
      &lt;body&gt;Hello, World! of Spring! &lt;%= java.time.LocalDateTime.now() %&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>This project runs okay on Tomcat 9. It displays the <em>Hello, World!</em> message. However, when I run on Tomcat 10, I get a 404 error message.</p>