Caused by: java.lang.ClassNotFoundException: jakarta.servlet.ServletRequest – Spring

by
Ali Hasan
parent-pom pom.xml spring spring-boot

Quick Fix: Generate a new pom.xml file using the Spring Initializr (spring.io/tools/initializr):

  1. Select the Web application type.
  2. Choose Java as the language and Spring Boot as the framework.
  3. Specify 2.7.0 as the Spring Boot version.
  4. Click the Generate button.

This will create a new project with the correct dependencies, including the Spring MVC and Jakarta EE APIs.

The Solutions:

Solution 1: Include Servlet Dependency in POM

Add the jakarta.servlet-api dependency to your POM file:

<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>4.0.3</version>
</dependency>

Video Explanation:

The following video, titled "How to resolve the Error: ClassNotFoundException org ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... Error: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet while running your Spring MVC based web ...