3

I am migrating a web application to a Spring Boot application which fails to start and displays the following error message :

    An attempt was made to call the method org.eclipse.jetty.server.Server. 
     <init>(Lorg/eclipse/jetty/util/thread/ThreadPool;)V but it does not 
     exist. 
     Its class, org.eclipse.jetty.server.Server, is available from the 
     following locations:

    jar:file:/C:/Users/xyz/.m2/repository/org/eclipse/jetty/jetty- 
    server/8.2.0.v20160908/jetty-server- 
    8.2.0.v20160908.jar!/org/eclipse/jetty/server/Server.class

    It was loaded from the following location:

    file:/C:/Users/xyz/.m2/repository/org/eclipse/jetty/jetty- 
    server/8.2.0.v20160908/jetty-server-8.2.0.v20160908.jar


    Action:

    Correct the classpath of your application so that it contains a single, 
    compatible version of org.eclipse.jetty.server.Server

As there is just one location (C:/Users/xyz/.m2/repository/org/eclipse/jetty/jetty- server/8.2.0.v20160908/jetty-server-8.2.0.v20160908.jar) as pointed by Spring Boot, there should be no ambiguity. I have provided all the required maven dependencies with version 8.2.0.v20160908. I have excluded tomcat dependency (spring-boot-starter-tomcat) from spring-boot-starter-web as I need to work with jetty. But I have NOT included jetty spring boot starter dependency in spring-boot-starter-web as I already have embedded jetty dependencies with group id org.eclipse.jetty defined through which jetty dependencies (jetty-server, jetty-servlet, jetty-security, jetty-http, jetty-util, jetty-webapp, jetty-xml, jetty-io, jetty-deploy etc) are provided.

The Spring Boot version is v2.1.1.RELEASE.

The jetty server is defined as spring bean which is as follows

      <bean id="webServer" class="org.someorg.server.jetty.Server">
        <property name="threadPool">
            <bean class="org.eclipse.jetty.util.thread.QueuedThreadPool">
                <property name="minThreads" value="8" />
                <property name="maxThreads" value="32" />
            </bean>
        </property>
        <property name="connectors">
            <list>
                <bean class="org.someorg.server.jetty.XmlConnector">
                    <property name="port" value="34347" />
                </bean>
                <bean class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
                    <property name="port" value="34346" />
                    <property name="keystore" value="classpath:keystore" />
                    <property name="password" value="somepassword" />
                    <property name="keyPassword" value="somekeypassword" />
                    <property name="truststore" value="classpath:keystore" />
                    <property name="trustPassword" value="sometrustpassword" 
      />
                </bean>
                <bean 
      class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                    <property name="port" value="34345" />
                </bean>
            </list>
        </property>
        <property name="handler">
            <bean class="org.eclipse.jetty.server.handler.HandlerCollection">
                <property name="handlers">
                    <list>
                        <ref bean="webContexts" />
                        <bean id="defaultHandler" 
       class="org.eclipse.jetty.server.handler.DefaultHandler" />
                    </list>
                </property>
            </bean>
        </property>
        <property name="beans">
            <list>
                <bean class="org.eclipse.jetty.deploy.WebAppDeployer">
                    <property name="contexts" ref="webContexts" />
                    <property name="webAppDir" value="webapps" />
                </bean>
            </list>
        </property>
        <property name="stopAtShutdown" value="false" />
     </bean>`

Class Server looks like the following :

public class Server extends org.eclipse.jetty.server.Server implements 
ApplicationListener<ApplicationContextEvent> {

 // code here

}

I am not sure here what Spring Boot is expecting here. I do not have any other jetty versions as I see in Maven Dependency Hierarchy. All maven dependencies are on classpath.

Any pointers ?

Thanks!

deepankardixit90
  • 351
  • 4
  • 19
  • I would suggest to remove that embedded container or not to use Spring Boot. You have competing containers. Also your container doesn't follow the principle that Spring Boot expects so it probably won't even work (reliably). – M. Deinum Jan 30 '19 at 10:10
  • @M.Deinum Thanks for responding. The app is a microservice actually. I am developing the microservice using using Spring Boot. So can't remove Spring Boot. – deepankardixit90 Jan 30 '19 at 10:26
  • Judging from your question you are moving to Spring Boot so why wouldn't you be able to remove it. – M. Deinum Jan 30 '19 at 10:26
  • Remove embedded container? I removed the default tomcat container from Spring Boot. I left the Jetty dependency (org.eclipse.jetty) as it is as I wanted to use the same. If I remove this as well I will need to use embedded Jetty from Spring Boot and make code change in classes depending on Jetty version 8.2 as there are changes between Jetty 8.2 and 9.4 which Spring Boot 2.1.1 will use. – deepankardixit90 Jan 30 '19 at 10:34
  • 2
    Spring Boot 2.1 doesn't work with Jetty 8.... – M. Deinum Jan 30 '19 at 10:42

2 Answers2

2

You are using a version of jetty incompatible to the selected version of spring boot.

spring-boot-starter-web 2.1.1.RELEASE depends on spring-web 5.1.3.RELEASE which depends on jetty-server 9.4.14.v20181114.

You'll have to upgrade your jetty dependency.

Selaron
  • 6,105
  • 4
  • 31
  • 39
  • I tried that but abandoned in between as that involved code changes in XMLConnectors (constructor etc have changes in few classes) used by Jetty. I will upgrade and make those changes and check if that resolves the issue. Thanks for the response. – deepankardixit90 Jan 30 '19 at 10:29
  • 2
    @raghav Migration and upgrading always comes at a cost ;) – Selaron Jan 30 '19 at 10:36
0

I am upgrading from spring boot 1.x to 2.7.11

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
        </dependency>  

But getting .... Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory and org.eclipse.jetty.server.session.SessionHandler