perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Jetty `NoSuchMethodError` when updating to 2.8.0 #1099

Open NicMcPhee opened 5 years ago

NicMcPhee commented 5 years ago

Our system runs fine on 2.7.2, but when I try to update to 2.8.0 Spark fails to start with:

Exception in thread "Thread-1" java.lang.NoSuchMethodError: spark.embeddedserver.jetty.JettyHandler.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig;
        at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:52)
        at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:80)
        at spark.Service.lambda$init$2(Service.java:566)
        at java.lang.Thread.run(Thread.java:748)

It looks like EmbeddedJettyFactory is referring to a method (getSessionCookieConfig()) in JettyHandleer that doesn't exist. JettyHandler hasn't been changed in 3 years, so I'm guessing maybe there's an update that didn't get merged in? Don't know why this fails for us and no one else, though.

Our dependencies are:

dependencies {
  compile 'com.sparkjava:spark-core:2.8.0'
  compile 'com.sparkjava:spark-debug-tools:0.5'
  compile 'org.slf4j:slf4j-simple:1.7.26'
  compile 'com.google.code.gson:gson:2.8.5'
  compile 'org.mongodb:mongodb-driver:3.10.1'

  testCompile 'junit:junit:4.12'
}

Many thanks for your help.

parambirs commented 5 years ago

I faced the same problem. Removing the dependency on spark-debug-tools fixed the exception. The spark-debug-tools package hasn't been updated for a few years now.

NicMcPhee commented 5 years ago

Thanks to @parambirs – that does fix the problem for us as well. Not thrilled that we have to drop the debugging tools, but it's nice that you were able to isolate the problem to spark-debug-tools. (This is actually upgrading to v2.9.1 since that's the current latest version, but we had the same error on 2.9.1 as we did on 2.8.0.)

philthompson commented 4 years ago

i ran into this problem when following the spark "Basic webapp structure" tutorial and building with gradle. after updating to spark-core 2.8 and above, my project was somehow using an outdated version of org.eclipse.jetty:jetty-server. for example the newest release of jetty-server, version 9.4.21.v20190926, contains the SessionHandler.getSessionCookieConfig() method.

switching from gradle to maven worked for me -- this was easier than digging into why gradle wasn't keeping dependencies up-to-date.

NicMcPhee commented 3 years ago

One option if you're not into Spark too deeply is to switch to Javalin https://github.com/tipsy/javalin, which is arguably the spiritual successor to Spark. We switched over about a year ago, and have been happy with that decision.

On Thu, Apr 15, 2021 at 6:25 AM Gautam Chaurasia @.***> wrote:

Even I'm using 2.9.3</spark.version> but still getting below error. Not even using spark-debug-tools.

Pls suggest !!

Exception in thread "Thread-0" java.lang.NoSuchMethodError: 'javax.servlet.SessionCookieConfig spark.embeddedserver.jetty.JettyHandler.getSessionCookieConfig()' at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:52) at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:80) at spark.Service.lambda$init$2(Service.java:624) at java.base/java.lang.Thread.run(Thread.java:829)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/perwendel/spark/issues/1099#issuecomment-820348879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACJZWO2PUIP2ASIXSL64CTTI3EK7ANCNFSM4G5DO7NA .