Search code examples
javaspringspring-bootjettywiremock

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.


Solution

  • 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>