2

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.

Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82

4 Answers4

1

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>
Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82
1

I know the problem is already solved. But worth mentioning maybe help other in future if they have same problem. I had the same error but in my case there was another dependency which bring jetty server in addition to spring-boot. With

mvn dependency:tree

I figure out two different version of Jetty was pulled to my project. I just exclude Jetty server from external dependency in maven and every thing worked fine.

        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-jetty9</artifactId>
            <version>${metrics.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-server</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
Neyma
  • 193
  • 3
  • 9
0

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.

  • Do I need to exclude a specific jetty library? They have a set of things such as servlets, core, server, client, and more. – Dmytro Chasovskyi Mar 15 '21 at 16:23
  • I think, that you should either import dependency management from the `org.springframework.boot:spring-boot-dependencies:2.4.3` or try to use same versions as defined there in your project. So, I don't think, that you have to exclude something. – Radim Tlusty Mar 15 '21 at 16:27
  • I made an update of my post. It looks like it all gets messed up because of Wiremock and incompatible jetty versions. Do you have any other ideas? – Dmytro Chasovskyi Mar 16 '21 at 10:20
0

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>
Abdulsamet ILERI
  • 155
  • 2
  • 10