4

If I put the latest org.apache.tomcat.embed:tomcat-embed-core:10.1.0-M16 dependecy, it will make the import javax.servlet.http.HttpServletResponse cannot be resolve.

Here's my build.gradle,

plugins {
    id 'org.springframework.boot' version '2.7.0'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'war'
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.apache.tomcat.embed:tomcat-embed-core:10.1.0-M16'
}

How do I fixed this?

Thank you!

Ricky Vene
  • 105
  • 1
  • 11
  • Does this answer your question? [Servlet 5.0 JAR throws compile error on javax.servlet.\* but Servlet 4.0 JAR does not](https://stackoverflow.com/questions/64387472/servlet-5-0-jar-throws-compile-error-on-javax-servlet-but-servlet-4-0-jar-does) – Olaf Kock Jul 05 '22 at 10:20

1 Answers1

6

tomcat-embed-core:9.0.63 provided by Spring Boot also contained repackaged classes from javax.servlet-api library, but they are no longer present in 10.1 branch due to migration from javax.servlet to jakarta.servlet. You could manually add this dependency to fix the compilation error:

compileOnly 'javax.servlet:javax.servlet-api:4.0.1'

However, this alone won't fix the issue, as Spring Boot 2.7 is just not internally compatible with Tomcat 10.1 because of its migration from javax.servlet to Jakarta APIs. If you want to try Tomcat 10.1 with Spring Boot, you'd most probably have to wait until Spring Boot 3 comes out. See more info in Spring Boot blog.

Forketyfork
  • 7,416
  • 1
  • 26
  • 33