JacksonJsonSupport 特征导致 initialize() 的 NoSuchMethodError

JacksonJsonSupport trait causes a NoSuchMethodError for initialize()

我正在查看 Scalatra 2.4 的 Scalatra "Handling JSON" tutorial,我得到了 "NoSuchMethodError":

Exception in thread "main" java.lang.NoSuchMethodError: org.scalatra.json.JacksonJsonSupport$class.initialize(Lorg/scalatra/json/JacksonJsonSupport;Ljava/lang/Object;)V
    at com.tutorial.FlowersController.initialize(FlowersController.scala:8)
    at com.tutorial.FlowersController.initialize(FlowersController.scala:8)
    at org.scalatra.ScalatraServlet$class.init(ScalatraServlet.scala:123)
    at com.tutorial.FlowersController.init(FlowersController.scala:8)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:595)
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:385)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:862)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:300)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.server.Server.start(Server.java:357)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.server.Server.doStart(Server.java:324)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.runner.Runner.run(Runner.java:509)
    at org.eclipse.jetty.runner.Runner.main(Runner.java:557)

我在控制器签名后添加了 "with JacksonJsonSupport" 和 "protected implicit lazy val jsonFormats: Formats = DefaultFormats"。我在顶部有两个导入,import org.json4s.{DefaultFormats, Formats} 和 import org.scalatra.json._

为了完整起见,我的 ScalatraBootstrap 没有包声明,如下所示:

import com.tutorial._
import org.scalatra._
import javax.servlet.ServletContext

class ScalatraBootstrap extends LifeCycle {
  override def init(context: ServletContext) {
    context.mount(new FlowersController, "/*")
  }
}

我将 "org.scalatra" %% "scalatra-json" % ScalatraVersion 和 "org.json4s" %% "json4s-jackson" % "3.3.0" 添加到 build.scala 并重新启动某人。我错过了什么?

我用 "sbt clean" 得到了它。该教程建议重新启动 sbt 以下载新的 jar,然后再次检查它,它工作正常,但我最初的尝试显然不太正确。我能想到的唯一区别是,我是 运行 在 Docker 容器中的初步尝试,也许有些地方并不完美。