Tomcat 出现 scalatra 错误 - NoSuchMethodError HttpServletRequest.getContentLengthLong

Tomcat with scalatra Error - NoSuchMethodError HttpServletRequest.getContentLengthLong

当我尝试 运行 Tomcat 中的程序时出现以下错误:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getContentLengthLong()J
org.scalatra.servlet.HttpServletRequestReadOnly.<init>(HttpServletRequestReadOnly.scala:56)
org.scalatra.ScalatraContext$class.scalatraContext(ScalatraContext.scala:71)

我正在使用 Scalatra 和 Tomcat 7,我正在尝试使用 (akka actor) 执行 AsyncResult。 我正在使用 maven,我的依赖项如下

<!-- https://mvnrepository.com/artifact/org.scalaj/scalaj-http_2.11 -->
    <dependency>
        <groupId>org.scalaj</groupId>
        <artifactId>scalaj-http_2.11</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.5</version>
    </dependency>
    <dependency>
        <groupId>org.scalatra</groupId>
        <artifactId>scalatra_2.11</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>org.scalatra</groupId>
        <artifactId>scalatra-scalate_2.11</artifactId>
        <version>2.5.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor_2.11 -->
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor_2.11</artifactId>
        <version>2.4.16</version>
    </dependency>

    <dependency>
        <groupId>com.datastax.spark</groupId>
        <artifactId>spark-cassandra-connector_2.11</artifactId>
        <version>2.0.0-M3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.scala-lang/scala-reflect -->
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-reflect</artifactId>
        <version>2.11.8</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.scala-lang/scala-compiler -->
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-compiler</artifactId>
        <version>2.11.8</version>
    </dependency>


    <!--Spark dependencies-->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.11</artifactId>
        <version>2.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.11 -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.11</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.databricks</groupId>
        <artifactId>spark-xml_2.11</artifactId>
        <version>0.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.json4s</groupId>
        <artifactId>json4s-native_2.11</artifactId>
        <version>3.5.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.scalatra/scalatra-swagger_2.11 -->
    <dependency>
        <groupId>org.scalatra</groupId>
        <artifactId>scalatra-swagger_2.11</artifactId>
        <version>2.5.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.scalatra/scalatra-json_2.11 -->
    <dependency>
        <groupId>org.scalatra</groupId>
        <artifactId>scalatra-json_2.11</artifactId>
        <version>2.5.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/net.databinder.dispatch/dispatch-core_2.11 -->
    <dependency>
        <groupId>net.databinder.dispatch</groupId>
        <artifactId>dispatch-core_2.11</artifactId>
        <version>0.11.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml_2.11 -->
    <dependency>
        <groupId>org.scala-lang.modules</groupId>
        <artifactId>scala-xml_2.11</artifactId>
        <version>1.0.6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.scalatest/scalatest_2.11 -->
    <dependency>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest_2.11</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>

我收到错误的行代码是

new AsyncResult {
    val is =
      Future {

我尝试了包含依赖项、排除依赖项、添加依赖项...但我无法解决。有人知道怎么解决吗?

检查您的依赖关系树 - 您使用的版本可能依赖于较旧的 javax.servlet api。 HttpServletRequest.getContentLengthLong() 方法已添加到 Servlet API 3.1 中,如

中所述

http://docs.oracle.com/javaee/7/api/javax/servlet/ServletRequest.html#getContentLengthLong--

最后我使用 Tomcat 8 解决了这个问题,因为 tomcat 7 中包含的 javax-servlet 对我不起作用。