Restful Web service - java.lang.NoSuchMethodError

2020-04-17 05:52发布

问题:

I am trying one restful web service example so when I am going to hit url that time I am getting below exception

java.lang.NoSuchMethodError: jersey.repackaged.com.google.common.collect.Iterables.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;
    org.glassfish.jersey.server.internal.ConfigHelper.getContainerLifecycleListener(ConfigHelper.java:92)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:172)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:363)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:724)

Below are the Jars i am using

回答1:

This sort of error is usually caused by having an older version of Guava (or even google-collections) on the classpath in addition to the newer version you're trying to use.

This answer should help you find it and eliminate it.

https://stackoverflow.com/a/12044668/5856415



回答2:

Get rid of all the jars you currently have in the image, and download the distribution (RI Bundle). Add all the jars from this distribution into your project.

The problem you are currently facing is 1. you have a bunch or mismatched versions, and 2. you don't even have all the required jars.