title: DispatcherServlet cannot be cast to class jakarta.servlet.Servlet (ClassCastException)
body: <p>I have a similar problem to the one here <a href="https://stackoverflow.com/questions/17799295/classcastexception-dispatcherservlet-cannot-be-cast-to-servlet">DispatcherServlet cannot be cast to Servlet
  </a> which is when running a new Spring MVC project using Eclipse.
  However, all the answers suggest a solution using Maven and I'm not using Maven.</p>
  <p>I searched for a day for this problem but no solution.</p>
  <pre><code>INFO: Starting Servlet engine: [Apache Tomcat/10.0.4]
  Mar 22, 2021 9:59:10 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
  WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took 
  [447] milliseconds.
  
  Mar 22, 2021 9:59:10 AM org.apache.jasper.servlet.TldScanner scanJars
  INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for 
  this logger for a complete list of JARs that were scanned but no TLDs were found in them. 
  Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  
  
   Mar 22, 2021 9:59:11 AM org.apache.catalina.core.ApplicationContext log
   INFO: Marking servlet [dispatcher] as unavailable
  
   Mar 22, 2021 9:59:11 AM org.apache.catalina.core.StandardContext loadOnStartup
   SEVERE: Servlet [dispatcher] in web application [/spring-mvc-demo] threw load() exception
   java.lang.ClassCastException: class org.springframework.web.servlet.DispatcherServlet cannot 
   be cast to class jakarta.servlet.Servlet (org.springframework.web.servlet.DispatcherServlet 
   is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader 
   @62e70ea3; jakarta.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader 
   @8bd1b6a)
   
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1043)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:984)
  </code></pre>