Spring Boot 3 javax.servlet HttpServletRequest ClassNotFoundException fix
Codemia Knowledge Hub ·
Spring Boot 3 throws ClassNotFoundException for javax.servlet.http.HttpServletRequest because of the Jakarta migration. Boot 3 is built on Spring Framework 6, which moved from the javax.servlet namespace to jakarta.servlet, so you need jakarta.servlet.http.HttpServletRequest in your code and in every library on the classpath.
javax.servlet became jakarta.servlet
Before Spring Boot 3, servlet APIs came from packages such as javax.servlet.http. Jakarta EE 9 renamed them to jakarta.servlet.http. The classes are conceptually the same, but the package names differ, so bytecode that references javax.servlet.http.HttpServletRequest can no longer resolve in a Boot 3 application.
Any of these can trigger the exception:
- your own imports still use
javax.servlet.* - a filter, interceptor, or controller library was compiled against the old servlet API
- a third-party starter pulls in pre-Jakarta dependencies
- generated code or copied examples still reference
javax
Fixing your own imports
Controller and filter classes in Boot 3 must import the Jakarta servlet types.
If a class still imports javax.servlet.http.HttpServletRequest, it compiles only when old dependencies are present, which usually means the project is half-migrated.
Finding old servlet dependencies
The error can remain after you fix your imports if an older library still depends on javax.servlet. Authentication filters, servlet listeners and older Spring extensions are common culprits.
In Maven, inspect the dependency tree:
In Gradle:
Look for outdated libraries that still bring in javax.servlet-api or older Spring components. In a Boot 3 app, everything servlet-related should use Jakarta packages.
If you declare the servlet API yourself, make it the Jakarta one:
Most Spring Boot applications do not need this dependency directly, because the Boot starters manage it. Adding both the old and new servlet APIs only creates confusion.
Why it shows up during a 2.x to 3.x upgrade
The error is common during upgrades from Spring Boot 2.x to 3.x because most of the codebase looks compatible at first. Controllers, services and repositories often migrate cleanly, while servlet-related imports fail later, or only at runtime through reflective loading.
Filters are a typical place to miss. A migrated filter must use Jakarta imports throughout:
A single leftover javax import is enough to break it.
Mistakes that keep the error around
- Fixing only your own code. If a third-party library was compiled against
javax.servlet, you need a Jakarta-compatible version of that library. - Adding both
javax.servlet-apiandjakarta.servlet-api. This does not create compatibility. It causes classpath ambiguity and hides the real problem. - Assuming Tomcat is missing. In most Boot 3 applications the embedded server is fine. The problem is application or library bytecode that references the wrong package.
- Following Boot 2.x documentation. Security filters, custom servlet components and container customizers often need import changes plus dependency upgrades.
Related reading
- Why does Stream<T> not implement Iterable<T>?
- Why does sun.misc.Unsafe exist, and how can it be used in the real world?
- Why does the default parameterless constructor go away when you create one with parameters
- Why does the H2 console in Spring Boot show a blank screen after logging in?
- Why does the MongoDB Java driver use a random number generator in a conditional?
- Why does this Java program terminate despite that apparently it shouldn't and didn't?
- Why does Thread.isInterrupted always return false?
- Why doesn't Java allow generic subclasses of Throwable?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.