Upgrading to Spring Boot 3: cannot access javax.servlet.http.HttpServletRequest
07:16 09 Oct 2023

I'm migrating a project to Spring Boot 3.1.4 and I've switched out all my javax imports for jakarta. In one of my classes I have the following imports and when I try to create a new ServletWebRequest, my project will not compile due to "cannot access javax.servlet.http.HttpServletRequest.'

import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;


final WebRequest webRequest = new ServletWebRequest(request);

The request object I'm passing into the constructor is of type jakarta.servlet.http.HttpServletRequest.

I'm using spring-boot-starter-parent 3.1.4. I've noticed when running mvn dependency:tree that it shows org.springframework:spring-context:jar:5.3.26. However, If Im understanding https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html#appendix.dependency-versions.coordinates correctly it should be using org.springframework:spring-context:jar:6.0.12. I've successfully tried overriding to use 6.0.12 and the error still arises and prevents compilation.

I can't share my complete pom as its a multi-module project and also contains multiple private dependencies.

Adding the javax.servlet-api dependency into my pom and changing the imports back to javax allows the project to compile.

         
            javax.servlet
            javax.servlet-api
            3.0.1
            provided
        
maven jakarta-migration spring-boot-3