简体   繁体   中英

How to resolve nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/server/session/SessionDataStore?

I am migrating an old multi-module project. I cannot migrate as it has many dependencies, so I am making a single migration, hoping it will be easier.

I upgraded Spring-boot to version 2.4.3 and constantly getting these errors:

Caused by: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JettyServletWebServerFactory' defined in class path resource [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 . I hope there is no need to patch the wiremock or rewrite the test codebase.

On the Jetty Github issue, I got an answer that resolved my issue to use jetty-bom , so jetty can take care of itself:

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

It worked seamlessly for me.

UPDATE:

It worked seamlessly until I did mvn clean install , so another dependency that absolutely necessary in my case:

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

Spring Boot 2.4.3 is based on Jetty 9.4.38.v20210224. The class SessionDataStore reported in the NoClassDefFoundException isn't present in the Jetty version, which you are using.

So, the solution will be probably to upgrade to Jetty 9.4.38.v20210224.

I fixed this issue by upgrading com.github.tomakehurst from 2.27.2 to 2.34.0 like shown below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM