玩吧! 3.0 NoSuchMethodError:'com.google.inject.Provider com.google.inject.util.Providers.guicify(javax.inject.Provider)'

问题描述 投票:0回答:1

我刚刚回到我的一个旧的 Play! 框架项目,该项目从

2.6.0
版本开始,并已更新到
3.0.2

版本

修复错误并更新项目进行编译后,我开始运行它了!但是,当我点击

localhost:9000
时,我立即收到运行时错误:

NoSuchMethodError: 'com.google.inject.Provider com.google.inject.util.Providers.guicify(javax.inject.Provider)'
play.api.inject.guice.GuiceableModuleConversions$$anon$4.$anonfun$configure$3(GuiceInjectorBuilder.scala:376)
     scala.Option.foreach(Option.scala:437)
     play.api.inject.guice.GuiceableModuleConversions$$anon$4.$anonfun$configure$2(GuiceInjectorBuilder.scala:375)
     play.api.inject.guice.GuiceableModuleConversions$$anon$4.$anonfun$configure$2$adapted(GuiceInjectorBuilder.scala:372)
     scala.collection.immutable.List.foreach(List.scala:334)
...
org.apache.pekko.stream.impl.fusing.MapAsyncUnordered$$anon$31.onPush(Ops.scala:1443)
...
org.apache.pekko.dispatch.Mailbox.exec(Mailbox.scala:253)
...
java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

我已经为此绞尽脑汁好几天了,现在主要做这样的事情:

  • 更新/更改 Scala 版本。目前正在

    3.3.3

  • 清除

    ~/.ivy2
    ~/Library/Caches/Coursier/v1/https/repo1.maven.org

  • build.sbt
    调整

这是我的

build.sbt

name := """my-api"""
organization := "DEV LLC"

version := "1.0-SNAPSHOT"

scalaVersion := "3.3.3"

resolvers += "Typesafe Repository" at "https://mvnrepository.com/artifact/com.typesafe.akka/akka-stream"

libraryDependencies += filters
libraryDependencies += jdbc
libraryDependencies += ws
libraryDependencies += guice
// libraryDependencies += "com.google.inject" % "guice" % "4.2.0"
// libraryDependencies += "com.google.inject" % "guice" % "7.0.0"
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.24"
libraryDependencies += "org.json4s" %% "json4s-native" % "4.0.7"
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "7.0.0" % "test"
libraryDependencies += "org.docx4j" % "docx4j-export-fo" % "3.3.0"
libraryDependencies += "org.jsoup" % "jsoup" % "1.9.2"
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "2.32.0"
libraryDependencies += "com.google.firebase" % "firebase-admin" % "5.9.0"
libraryDependencies += "net.codingwell" %% "scala-guice" % "7.0.0"
libraryDependencies += "org.apache.commons" % "commons-email" % "1.5"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

我的理论是玩!试图在运行时对动态加载的对象调用

guicify
,但失败并出现
NoSuchMethod
异常,这意味着我安装的
Guice
版本一定不是正确的版本。

如果这个理论是正确的,那么我仍然感到困惑,因为我已经验证我安装的 Guice 版本是 7.0

~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/google/inject/guice/7.0.0
并且
guicify
方法已添加到
4.x

寻求有关如何在这里前进的任何帮助或建议,因为我很困惑!

编辑:这是

sbt dependencyTree

的输出
+-org.playframework:play-guice_3:3.0.2
[info]   | +-com.google.inject.extensions:guice-assistedinject:6.0.0
[info]   | | +-com.google.errorprone:error_prone_annotations:2.18.0 (evicted by: 2.21..
[info]   | | +-com.google.errorprone:error_prone_annotations:2.21.1
[info]   | | +-com.google.inject:guice:6.0.0 (evicted by: 7.0.0)
[info]   | | +-com.google.inject:guice:7.0.0
[info]   | |   +-aopalliance:aopalliance:1.0
[info]   | |   +-com.google.guava:guava:31.0.1-jre (evicted by: 32.1.3-jre)
[info]   | |   +-com.google.guava:guava:32.1.3-jre
[info]   | |   | +-com.google.code.findbugs:jsr305:3.0.2
[info]   | |   | +-com.google.errorprone:error_prone_annotations:2.21.1
[info]   | |   | +-com.google.guava:failureaccess:1.0.1
[info]   | |   | +-com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-w..
[info]   | |   | +-com.google.j2objc:j2objc-annotations:2.8
[info]   | |   | +-org.checkerframework:checker-qual:3.37.0
[info]   | |   | 
[info]   | |   +-jakarta.inject:jakarta.inject-api:2.0.1
[info]   | |   
[info]   | +-com.google.inject:guice:6.0.0 (evicted by: 7.0.0)
[info]   | +-com.google.inject:guice:7.0.0


+-net.codingwell:scala-guice_3:7.0.0
[info]   | +-com.google.inject:guice:7.0.0
scala playframework pekko
1个回答
0
投票

简短回答:在类路径中使用/强制使用 Guice 6.x。 Play 目前依赖 6.x,尚未兼容 7.x。

将 scala-guice 降级到 6.x 应该足够了。


您收到的错误表明该方法不存在。需要知道的是,整个签名必须“兼容”才能被视为存在。

尤其是这里,

com.google.inject.util.Providers.guicify(javax.inject.Provider)
这个方法确实不存在。但
com.google.inject.util.Providers.guicify(jakarta.inject.Provider)
确实如此。

这是因为 Java(EE,现在的雅加达)生态系统发生重大变化,迫使某些包重命名。

Guice,依靠这些软件包,已经发布了两个支持其中一个名称的版本

  • 6.0.0(支持javax.{inject,servlet,persistence},主要支持jakarta.inject)
  • 7.0.0(支持 jakarta。{注入,servlet,持久化})
  • (6.0.0 和 7.0.0 是等效的,除了它们的 javax/jakarta 支持。)

Guice 7.x 版本不再支持

javax.
软件包。

© www.soinside.com 2019 - 2024. All rights reserved.