maven - 带有 scalatra 错误的 Tomcat - NoSuchMethodError HttpServletRequest.getContentLengthLong

标签 maven tomcat scalatra

当我尝试在 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--

关于maven - 带有 scalatra 错误的 Tomcat - NoSuchMethodError HttpServletRequest.getContentLengthLong,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42367193/

相关文章:

maven - 由于 Maven 依赖关系,尝试运行新的 grails 项目失败

Eclipse:使用 Jetty 和 Tomcat 进行调试不起作用

tomcat - 当我尝试打开任何其他网页时,为什么会出现 Tomcat 的欢迎页面?

Scalatra 无法找到或加载主类

scalatra - 如何使用 Scalatra 将文件发送到浏览器?

maven - Spring Boot 无法识别 mvn liquibase cli 更改,反之亦然

java - mvn tomcat :run resolving jSTL taglibs dependencies

java - maven-bundle-plugin 不包含 Import-Package

ruby-on-rails - 当使用 jruby-rack 部署到 tomcat 时,防止 Rails 打开 production.log

没有 SBT 的 Scalatra