chris
chris

Reputation: 1894

Java Spark server NoSuchMethodError

Here is the code in question:

post("user/login ", (request, response) -> {
            return "hello";
});

And here is the error that happens right after the return statement:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeaders(Ljava/lang/String;)Ljava/util/Collection;
    at spark.utils.GzipUtils.checkAndWrap(GzipUtils.java:64)
    at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:251)
    at spark.webserver.JettyHandler.doHandle(JettyHandler.java:61)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
    at org.eclipse.jetty.server.Server.handle(Server.java:517)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:302)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:745)

From what I've read, there is some version problem in my jars - here are the jars I'm using:

jar versions

I am using maven, and followed the directions found in Spark's documentation. How can I get past this error?

Upvotes: 1

Views: 1703

Answers (2)

kinkajou
kinkajou

Reputation: 3728

I went to File> Project Structure> Libraries and then deleted javax.servlet-api 2.5 (kept 3.1.0).

Upvotes: 0

chris
chris

Reputation: 1894

Found it! I printed out everything on the classpath. Here are a few of the entries:

...../lib/javax.servlet-api-3.1.0.jar 
...../idea-IU-143.1821.5%20(2)/lib/servlet-api.jar

Turns out Intellij was loading something I didn't know about (maybe I caused it to do that, not sure) that conflicted with the jar I needed. I went into that directory and renamed the Intellij jar. It's apparently causing some problem in Intellij (it reported some internal IDE error) but my code works now.

I wonder why Intellij's jars would ever have anything to do with my project... yikes.

Upvotes: 4

Related Questions