Home > database >  NoClassDefFoundError jakarta/servlet/http/HttpSessionContext after upgrade to spring boot 3
NoClassDefFoundError jakarta/servlet/http/HttpSessionContext after upgrade to spring boot 3

Time:01-02

In my gradle base project I'm trying upgrade spring dependency from 2.7.6 to 3.0.1,

However I face issue NoClassDefFoundError: jakarta/servlet/http/HttpSessionContext

Caused by: java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpSessionContext
    at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:339)
    at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:432)
    at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:257)
    at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:180)
    at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:301)
    at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:228)
    at org.springframework.boot.web.embedded.jetty.JettyEmbeddedWebAppContext.<init>(JettyEmbeddedWebAppContext.java:28)
    at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:158)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161)
    ... 9 common frames omitted
Caused by: java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 19 common frames omitted

As I understand spring boot 3.0 use Servlet Api 6.0 which is not supported by Jetty and it requires downgrade Servlet API to 5.0.0 (https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jetty)

CodePudding user response:

To solve this issue, you need to add to your gradle.build script ext['jakarta-servlet.version'] = '5.0.0'

  • Related