【问题标题】:No such method error akka.util.Helpers$.toRootLowerCase(Ljava/lang/String;)Ljava/lang/String;没有这样的方法错误 akka.util.Helpers$.toRootLowerCase(Ljava/lang/String;)Ljava/lang/String;
【发布时间】:2017-09-26 23:52:24
【问题描述】:

我正在尝试运行以下程序

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.directives.BasicDirectives
import akka.io.IO
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory
import spray.json.DefaultJsonProtocol
import scala.concurrent.duration._
import scala.concurrent.Await


trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
  implicit val itemFormat = jsonFormat2(Item)
}


final case class Item(name: String, id: Long)

object Main extends App with RestInterface {


  val config = ConfigFactory.load()
  val host = config.getString("http.host")
  val port = config.getInt("http.port")


  implicit val system = ActorSystem("My-ActorSystem")
  implicit val executionContext = system.dispatcher
  implicit val materializer = ActorMaterializer()
  //implicit val timeout = Timeout(10 seconds)

  val api = routes

  Http().bindAndHandle(api, host, port) map {
    binding => println(s"The binding local address is ${binding.localAddress}")
  }
  //  recover
  //    { case ex => println(s"some shit occurred and it is"+ex.getMessage) }


  //  sys.addShutdownHook {
  //    system.log.info("Shutting down Spray HTTP in 10 seconds...")
  //    // NOTE(soakley): We are waiting to unbind to allow the VIP time to query healthcheck status.
  //    Thread.sleep(10000)
  //    system.log.info("Shutting down Spray HTTP and allowing 10 seconds for connections to drain...")
  //    val unbindFuture =  Http.unbind(10.seconds)
  //
  //    Await.ready(unbindFuture, 10.seconds)
  //  }



}



case class Stringer(str1 : String, str2 : String, str3 : String)


trait RestInterface extends Resource {

  val routes = questionroutes ~ mydirectiveroute01 ~ mydirectiveroute02

}

trait Resource extends QuestionResource with mydirective01 with mydirective02

trait QuestionResource {
  val questionroutes = {
    path("hi") {
      get {

        val stringer_instance = Stringer("questionairre created","whatever","whatever-whatever")

        complete(ToResponseMarshallable(stringer_instance.toString()))
      }
    }
  }
}


trait mydirective01 extends BasicDirectives {

  val getandputdirective = get | put

  val mydirectiveroute01 = {



    path("customhi" / IntNumber) {
      passednumber1 => {

        path(IntNumber) {

          passednumber2 => {

            getandputdirective {
              ctx =>
                ctx.complete("Testing get and put directive" + s"The passed string is " + passednumber2 + passednumber1)
            }
          }
        }
      }
    }

  }
}


trait mydirective02 extends BasicDirectives with JsonSupport {

  val mydirectiveroute02 =
    path("hello") {
      get {
        complete(HttpEntity(
          ContentTypes.`text/html(UTF-8)`,
          "<h1>Say hello to akka-http</h1>"))
      }
    } ~
      path("randomitem") {
        get {
          // will marshal Item to JSON
          complete(Item("thing", 42))
        }
      } ~
      path("saveitem") {
        post {
          // will unmarshal JSON to Item
          entity(as[Item]) { item =>
            println(s"Server saw Item : $item")
            complete(item)
          }
        }
      }
}

但我收到以下错误

线程“主”java.lang.NoSuchMethodError 中的异常:akka.util.Helpers$.toRootLowerCase(Ljava/lang/String;)Ljava/lang/String;

错误似乎是因为这一行

隐式 val materializer = ActorMaterializer()

请问我哪里出错了。我有相同的 pom.xml 文件和另一个模块中的程序,它似乎运行良好。我不明白我哪里出错了。谢谢

【问题讨论】:

  • 你使用的是哪个 jdk 和 scala 版本?

标签: scala rest maven akka


【解决方案1】:

当应该重新编译的东西没有重新编译时,我会收到类似的错误。 clean" 后跟 sbt 中的 "compile" 解决它。

【讨论】:

    【解决方案2】:

    此问题是由于依赖项冲突造成的,请确保您对要导入的所有相关包使用相同的版本。

    example:
     <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-http-core_2.11</artifactId>
            <version>10.0.0</version>
        </dependency>
    

    2.11 确保您有其他相同版本的依赖项 然后进行干净的构建。

    【讨论】:

      【解决方案3】:

      您的项目依赖项具有冲突的版本。具有该功能的版本将被丢弃,而 jar 中包含的另一个版本(或类路径 - 取决于您的执行方式)。 请提供您的依赖文件(即sbt.buildgradle.build 等)

      【讨论】:

        猜你喜欢
        • 2016-02-07
        • 2018-01-16
        • 1970-01-01
        • 2014-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多