如何解决嵌套异常是 java.lang.NoClassDefFoundError: org/eclipse/jetty/server/session/SessionDataStore?

我正在迁移一个旧的多模块项目。我无法迁移,因为它有很多依赖项,所以我进行了一次迁移,希望它会更容易。

我将 Spring-boot 升级到 2.4.3 版本并不断收到以下错误:

原因:org.springframework.context.ApplicationContextException:无法启动Web服务器;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedJetty.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory]: Factory method 'JettyServletWebServerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/server/session/SessionDataStore at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)

My version of the jetty is 9.2.28.v20190418.

I am breaking my head trying to resolve this issue but made no progress.

How can I resolve it?

UPDATE:

I tried downgrading Spring Boot to 2.3.3.RELEASE, I tried upgrading all jetty components to 11.0.1, no difference. It gets to less clear, more marginal error messages.

UPDATE 2:

When I start the Spring boot app itself, I got a message:

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.configureSession(JettyServletWebServerFactory.java:242)

The following method did not exist:

'void org.eclipse.jetty.server.session.SessionHandler.setMaxInactiveInterval(int)'

The method's class, org.eclipse.jetty.server.session.SessionHandler, is available from the following locations:

jar:file:/Users/dmytro/.m2/repository/org/eclipse/jetty/jetty-server/9.2.28.v20190418/jetty-server-9.2.28.v20190418.jar!/org/eclipse/jetty/server/session/SessionHandler.class

I still cannot understand how to solve it as I didn't work with Jetty too much before, but it looks like something.

UPDATE 3:

After endless hours of debugging, I figured out that the conflict arises between wiremock:2.27.2 and spring-boot:2.4.3. They both depend on incompatible versions of jetty, jetty:9.2.28.v20190418 and jetty:9.4.38.v20210224.

The issue is that I cannot remove the wiremock. I cannot downgrade Spring Boot, as wiremock is lagging. Whats other alternatives do I have?

UPDATE 4: I posted an issue on GitHub 中定义的名称为“JettyServletWebServerFactory”的 bean 时出错。我希望不需要修补wiremock或重写测试代码库。

stack overflow How to resolve nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/server/session/SessionDataStore?
原文答案
author avatar

接受的答案

在 Jetty Github 问题上,我得到的答案解决了我使用 jetty-bom 的问题,因此 jetty 可以自行处理:

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-bom</artifactId>
        <type>pom</type>
    </dependency>

它对我来说是无缝的。

更新:

在我执行 mvn clean install 之前,它一直无缝运行,因此在我的情况下另一个绝对必要的依赖项:

<dependency>
  <groupId>com.github.tomakehurst</groupId>
  <artifactId>wiremock-jre8</artifactId>
  <version>2.27.2</version>
  <type>pom</type>
</dependency>

答案:

作者头像

Spring Boot 2.4.3 基于 Jetty 9.4.38.v20210224。 SessionDataStore 中报告的类 NoClassDefFoundException 不存在于您正在使用的 Jetty 版本中。

因此,解决方案可能是升级到 Jetty 9.4.38.v20210224。

作者头像

我通过将 com.github.tomakehurst 从 2.27.2 升级到 2.34.0 解决了这个问题,如下所示

<dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock-jre8</artifactId>
        <version>2.34.0</version>
        <scope>test,compile</scope>
    </dependency>

相关问题