Springfox Type javax.servlet.http.HttpServletRequest not present
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This error usually appears when Springfox is used in a Spring Boot 3 application. Spring Boot 3 and Spring Framework 6 moved from javax.servlet to jakarta.servlet, while Springfox still expects the older servlet package in the failing scenarios most developers run into. The practical fix is usually not to hunt for one missing class, but to stop using an incompatible Springfox setup and switch to a Boot 3 compatible OpenAPI library.
Why the Error Happens
Older servlet-based libraries refer to javax.servlet.http.HttpServletRequest. In Spring Boot 3, the servlet stack is based on the Jakarta namespace, so the equivalent type is jakarta.servlet.http.HttpServletRequest.
That means an application can compile or start partially, then fail at runtime when a library tries to load a class that no longer exists in the expected package.
Typical trigger conditions are:
- Spring Boot 3 or Spring Framework 6
- Springfox 3 dependencies still on the classpath
- code or plugins built around the old
javax.*servlet API
This is fundamentally a compatibility problem, not a missing-import problem.
First Check Your Spring Boot Version
If you are on Spring Boot 3.x, assume jakarta.* everywhere in the web stack.
Check your dependency tree or build file first. A typical broken setup looks like this pattern:
That dependency line is a red flag in Boot 3 projects.
The Practical Fix: Replace Springfox With springdoc-openapi
For Spring Boot 3, a current springdoc-openapi starter is the usual replacement.
Maven example:
Gradle example:
Then remove Springfox dependencies and related configuration classes such as old Docket beans.
Minimal Boot 3 OpenAPI Example
After switching libraries, a normal controller is enough to generate docs.
With springdoc-openapi, the API docs are typically available at:
- '
/v3/api-docs' - '
/swagger-ui/index.html'
That is the supported direction for Boot 3 style applications.
If You Must Stay on Springfox
If a project cannot migrate immediately, the realistic option is to stay on an older Spring Boot line that still uses javax.servlet. That is a temporary compatibility choice, not a future-proof solution.
Trying to patch Boot 3 by manually adding an old servlet API jar is usually the wrong move. It creates classpath confusion and does not make Springfox truly compatible with the Jakarta-based runtime.
Clean Up Leftover Configuration
After migrating away from Springfox, remove any code tied specifically to it. A common leftover is a Swagger config class like this:
If that code remains after the dependency swap, the application still will not build cleanly.
Also check imports in custom code. If your own code still imports javax.servlet.http.HttpServletRequest, update it to the Jakarta equivalent when targeting Boot 3.
How to Diagnose Quickly
Useful commands:
These help confirm whether Springfox is still on the classpath somewhere through a transitive dependency.
Common Pitfalls
- Treating the issue as a single missing class instead of a Boot 3 and Jakarta compatibility problem.
- Adding legacy
javax.servletjars to a Boot 3 app and hoping the mismatch disappears. - Migrating the dependency but forgetting to remove old Springfox config beans.
- Updating imports in application code while leaving incompatible libraries untouched.
- Debugging controller code when the real problem is in API-doc tooling startup.
Summary
- '
javax.servlet.http.HttpServletRequesterrors in Boot 3 usually mean an old library is still expectingjavax.*.' - Springfox is the common culprit in this scenario.
- The usual fix is to replace Springfox with a Boot 3 compatible
springdoc-openapistarter. - Do not try to solve this by manually forcing old servlet jars into a Jakarta-based app.
- Remove both the dependency and the old Springfox configuration code during the migration.
Related reading
- SpringRunner vs SpringBootTest
- Spring's RequestParam with Enum
- Sprintf equivalent in Java
- SQL JPA - Multiple columns as primary key
- Spyder internal error while trying to open array
- SQL connection throws error when adding DistributedSession, SessionMiddleware
- SSH library for Java
- SSL handshake alert unrecognized_name error since upgrade to Java 1.7.0

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.