【问题标题】:how to resolve NoSuchMethodError on typesafe config?如何解决类型安全配置上的 NoSuchMethodError?
【发布时间】:2017-03-29 09:26:09
【问题描述】:

我在尝试运行我的项目时遇到此错误。

线程“主”java.lang.NoSuchMethodError 中的异常: com.typesafe.config.Config.getDuration(Ljava/lang/String;)Ljava/time/Duration;

试图清除 ivy2 缓存但没有成功。 这就是我构建 sbt 的样子:

scalaVersion  := "2.11.7"
scalacOptions := Seq("-unchecked", "-feature", "-deprecation", "-encoding", "utf8")

resolvers ++= Seq(
  Resolver.sonatypeRepo("releases"),
  Resolver.sonatypeRepo("snapshots"),
  Resolver.bintrayRepo("websudos", "oss-releases"),
  "spray repo"                       at "http://repo.spray.io",
  "Typesafe repository snapshots"    at "http://repo.typesafe.com/typesafe/snapshots/",
  "Typesafe repository releases"     at "http://repo.typesafe.com/typesafe/releases/",
  "Sonatype repo"                    at "https://oss.sonatype.org/content/groups/scala-tools/",
  "Sonatype releases"                at "https://oss.sonatype.org/content/repositories/releases",
  "Sonatype snapshots"               at "https://oss.sonatype.org/content/repositories/snapshots",
  "Sonatype staging"                 at "http://oss.sonatype.org/content/repositories/staging",
  "Sonatype"                         at "https://oss.sonatype.org/content/groups/public/",
  "Java.net Maven2 Repository"       at "http://download.java.net/maven/2/",
  "Twitter Repository"               at "http://maven.twttr.com"
)

libraryDependencies ++= {
  val phantomV         = "1.29.5"
  val scalaTestV       = "3.0.0"
  val elastic4sV       = "2.4.0"
  val akkaStreamVersion = "2.4.2"
  val akkaVersion = "2.3.11"
  Seq(
    "com.websudos"            %%  "phantom-dsl"                       % phantomV,
    "com.websudos"            %%  "phantom-reactivestreams"           % phantomV,
    "com.websudos"            %%  "util-testing"                      % "0.13.0"    % "test, provided",
    "com.typesafe.akka"       %% "akka-actor"                         % akkaVersion,
    "com.typesafe.akka"       %% "akka-http-spray-json-experimental"  % akkaStreamVersion,
    "com.typesafe.akka"       %%  "akka-http-core"                    % akkaStreamVersion,
    "com.typesafe.akka"       %% "akka-http-experimental"             % akkaStreamVersion,
    "com.typesafe.akka"       %% "akka-http-testkit"                  % akkaStreamVersion,
    "org.scalatest"           %% "scalatest"                          % scalaTestV % "test",
    "com.typesafe.akka"       %% "akka-testkit"                       % akkaVersion % "test",
    "com.typesafe.play"       %%  "play-streams-experimental"         % "2.4.6",
    "com.sksamuel.elastic4s"  %% "elastic4s-core"                     % elastic4sV,
    "com.sksamuel.elastic4s"  %% "elastic4s-streams"                  % elastic4sV
  )
}
lazy val root = project.in(file(".")).configs(IntegrationTest)
Defaults.itSettings

initialCommands := """|import akka.actor._
                      |import akka.pattern._
                      |import akka.util._
                      |import scala.concurrent._
                      |import scala.concurrent.duration._""".stripMargin
fork in run := true

知道如何解决吗?

更新: java.class.path 显示

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jps-builders.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/trove4j.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/scala-library.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/scala-nailgun-runner.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/compiler-settings.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/jps/nailgun.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/jps/sbt-interface.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/jps/incremental-compiler.jar:/Users/avi/Library/Application 支持/IntelliJIdea2016.2/Scala/lib/jps/scala-jps-plugin.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/dotty-interfaces.jar

【问题讨论】:

  • 您可能还想共享包含此getDuration 调用的代码行。
  • @mfirry 没有这样的行,即在代码中没有我明确调用此方法的地方。但是其他库可能正在调用,例如 scalatest/akka 等'
  • 我有兴趣查看更多信息/类型安全配置文件/这是完整的构建文件吗?
  • 哪个版本的 Typesafe config JAR 在类路径中? java.time.Duration getDuration(java.lang.String path) 在 1.3.0 中添加。也许您正在使用该库的早期版本。
  • @user2128014 谢谢,我怎么能看到?

标签: scala sbt typesafe-activator typesafe-config


【解决方案1】:

将 TypeSafe 1.3.1 添加为依赖项可能会有所帮助,请将其添加为依赖项的 Seq() 的一部分:

"com.typesafe" % "config" % "1.3.1"

【讨论】:

    【解决方案2】:

    这听起来像是一个类路径问题。您可能正在使用调用(使用)Typesafe Config 的库,但您路径中的 Typesafe Config 版本低于 1.3.0。 Typesafe Config 1.3.0 中引入了未找到的方法。要查看您的运行时类路径,请确保这些语句是最先执行的语句(即在您的应用崩溃之前):

    val cp = System.getProperty("java.class.path")
    val sep = System.getProperty("path.separator")
    cp.split(sep).foreach(println)
    

    一旦您发现没有 Typesafe Config 1.3.0,请将其添加为显式依赖项。

    【讨论】:

    • 将其添加为显式依赖解决了该问题 - 谢谢!
    • 你知道如何在 ivy repo 中修复它吗?
    • 如果你将它添加到你的依赖项中,你的构建系统(sbt?)应该将它下载到你的 Ivy repo。 (例如,sbt 使用 Ivy 进行依赖解析。)这不是发生过吗?
    • 如果你使用的是 sbt,sbt update 会下载缺失的依赖项
    猜你喜欢
    • 2014-08-21
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    相关资源
    最近更新 更多