Home > Software engineering >  tomcat-embed-core:10.1.0-M16 will make the import javax.servlet.http.HttpServletResponse cannot be r
tomcat-embed-core:10.1.0-M16 will make the import javax.servlet.http.HttpServletResponse cannot be r

Time:07-05

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!

CodePudding user response:

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.

  • Related