Springfox
HttpServletRequest
Java
Servlet
Troubleshooting

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.

Browse interview questions

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:

xml
1<dependency>
2    <groupId>io.springfox</groupId>
3    <artifactId>springfox-boot-starter</artifactId>
4    <version>3.0.0</version>
5</dependency>

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:

xml
1<dependency>
2    <groupId>org.springdoc</groupId>
3    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
4    <version>2.8.15</version>
5</dependency>

Gradle example:

gradle
dependencies {
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.15'
}

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.

java
1package com.example.demo;
2
3import org.springframework.web.bind.annotation.GetMapping;
4import org.springframework.web.bind.annotation.RestController;
5
6@RestController
7public class HelloController {
8
9    @GetMapping("/hello")
10    public String hello() {
11        return "ok";
12    }
13}

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:

java
1@Bean
2public Docket api() {
3    return new Docket(DocumentationType.SWAGGER_2);
4}

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:

bash
./mvnw dependency:tree | grep -i springfox
./gradlew dependencies | grep -i springfox

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.servlet jars 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.HttpServletRequest errors in Boot 3 usually mean an old library is still expecting javax.*.'
  • Springfox is the common culprit in this scenario.
  • The usual fix is to replace Springfox with a Boot 3 compatible springdoc-openapi starter.
  • 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
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track 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.

Browse interview questions

All Rights Reserved.