最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java.lang.ClassNotFoundException: javax.servlet.ServletContext error using Jetty 12 EE10 Jakarta namespace with Spring Boot 3.2

programmeradmin1浏览0评论

I'm running Jetty 12.0.15 with Spring Boot 3.2.12. My code is all Jakarta namespace and I'm using Jakarta Servlet 6.0.0 which is now supported. All my config works fine when I run the app from Eclipse with embedded Jetty. However when I start the app from a normal standalone Jetty server, I get class not found for javax.servlet.ServletContext as follows.

Caused by:
java.lang.ClassNotFoundException: javax.servlet.ServletContext
        at java.base/java.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at org.eclipse.jetty.ee10.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:494)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
        at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:320)
        at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:149)
        at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:413)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:336)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:246)
        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:534)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:321)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:246)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:197)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
...

I'm not including any of the Jetty artifacts in my WAR. I know that can cause problems. And I'm including all ee10 Jakarta versions of the jetty modules for the server and not the others when using start.jar --add-modules.

Anybody have any ideas why it's generating this exception? I don't know what dependency is resolving incorrectly. Are incorrect Jetty modules causing this? If so, which Jetty modules should I be including?

I'm running Jetty 12.0.15 with Spring Boot 3.2.12. My code is all Jakarta namespace and I'm using Jakarta Servlet 6.0.0 which is now supported. All my config works fine when I run the app from Eclipse with embedded Jetty. However when I start the app from a normal standalone Jetty server, I get class not found for javax.servlet.ServletContext as follows.

Caused by:
java.lang.ClassNotFoundException: javax.servlet.ServletContext
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at org.eclipse.jetty.ee10.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:494)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
        at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:320)
        at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:149)
        at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:413)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:336)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:246)
        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:534)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:321)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:246)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:197)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
...

I'm not including any of the Jetty artifacts in my WAR. I know that can cause problems. And I'm including all ee10 Jakarta versions of the jetty modules for the server and not the others when using start.jar --add-modules.

Anybody have any ideas why it's generating this exception? I don't know what dependency is resolving incorrectly. Are incorrect Jetty modules causing this? If so, which Jetty modules should I be including?

Share Improve this question edited Feb 7 at 9:54 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Feb 6 at 21:36 JasonJason 53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Nevermind. The issue was related to a transient dependency that was including a version of the artifact that was not Jakarta compliant which was causing the issue.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论