java.lang.NoSuchMethodError while starting JAX-RS service via Spring (servlet) configuration

StackOverflow https://stackoverflow.com/questions/23325820

  •  10-07-2023
  •  | 
  •  

Question

I have a question. I'm still new to Spring Framework and how to configure a Jetty server with Apache CXF and JAX-RS services there.

I'm working on a Maven multi-module project and my module is just one part of that whole project. It's written in Java. And it uses the Spring Framework with Spring Beans/BeanFactory there. It's configured in an XML file there.

I followed those documentations:
- http://cxf.apache.org/docs/jetty-configuration.html
- http://cxf.apache.org/docs/jax-rs.html#JAX-RS-ConfiguringJAX-RSservices
- http://cxf.apache.org/docs/secure-jax-rs-services.html

The JAX-RS service is running so far already, but it shows me an empty webpage then. It also shows me in a LOG file that the Java classes (with the JAX-RS annotations @GET, @PUT and so on) of the JAX-RS service are running and called already, but as soon as I send a request, I receive the following error message:

27 Apr 2014 20:05:53 (cdmi) [] /
java.lang.NoSuchMethodError: org.eclipse.jetty.server.Request.getConnection()Lorg/eclipse/jetty/server/HttpConnection;
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:222) ~[cxf-rt-transports-http-jetty-2.4.0.jar:2.4.0]
    at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72) ~[cxf-rt-transports-http-jetty-2.4.0.jar:2.4.0]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.Server.handle(Server.java:370) ~[jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) [jetty-http-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) [jetty-http-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264) [jetty-server-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-8.1.13.v20130916.jar:8.1.13.v20130916]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-8.1.13.v20130916.jar:8.1.13.v20130916]
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_55]

Does someone know this error message. What is the error message trying to tell me and how can I solve it?

I'm not sure which further information might be required, but I can add that information if necessary. The dependency for cxf-rt-transports-http-jetty (version 2.4.0) exists in the POM.xml file of my Maven module.

Many thanks in advance!!!

Was it helpful?

Solution

NoSuchMethodError basically means that a class definition has changed between compile time and runtime. This can be caused by using a different version of a jar when running your application than the version things were compiled with.

It looks like sometime between Jetty 8 and 9 the getConnection method was removed from Request. I would check your target folder to make sure you don't have multiple versions of any jars and that the versions you are using are compatible with each other. Also make sure that however you are running Jetty, it's the same version as the libraries your application depends on.

You might also run maven dependency:tree to check that versions in your pom aren't being overridden in unexpected ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top