HendPro12
HendPro12

Reputation: 1104

Upgrading to Spring Boot 3: cannot access javax.servlet.http.HttpServletRequest

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.

         <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

Upvotes: 0

Views: 9581

Answers (1)

HendPro12
HendPro12

Reputation: 1104

I discovered that a dependency in my pom.xml for org.springdoc had a parent of spring-boot-starter-parent 2.7.10 which was responsible for the introduction of other spring dependencies with version 6.0.12.

Upvotes: 0

Related Questions