添加 slf4j/logback 时 akka-http 崩溃

akka-http crashes when adding slf4j/logback

我有一个可用的 akka-http 应用程序。现在我尝试通过 slf4j 和 logback 添加日志记录,但我的应用程序崩溃了。

build.sbt

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-http" % "10.0.7",
  "ch.qos.logback" % "logback-classic" % "1.2.3",
  "com.typesafe.akka" %% "akka-slf4j" % "2.5.2"
)

application.conf

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

错误:

Detected java.lang.NoSuchMethodError error, which MAY be caused by incompatible Akka versions on the classpath. Please note that a given Akka version MUST be the same across all modules of Akka that you are using, e.g. if you use akka-actor [2.5.2 (resolved from current classpath)] all other core Akka modules MUST be of the same version. External projects like Alpakka, Persistence plugins or Akka HTTP etc. have their own version numbers - please make sure you're using a compatible set of libraries.

Uncaught error from thread [my-system-akka.actor.default-dispatcher-6] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[my-system] java.lang.NoSuchMethodError: akka.actor.ActorCell.addFunctionRef(Lscala/Function2;)Lakka/actor/FunctionRef;

根据消息,这是一个兼容性问题。我如何找出 akka-httpakka-slf4j 的哪些版本兼容(试用除外)?

附带说明,因为这是一个类似的问题:我想添加 akka-stream。但是,使用最新版本的 akka-httpakka-stream 会在 sbt 中给出驱逐警告。与上述相同的问题:如何找出要使用的版本?

不幸的是,akka-http 的版本与 akka 的其余部分分开,并且它的最新版本不一定使用 akka 的最新版本。在 akka-http 版本 10.0.7 的情况下,兼容的 akka 版本是 2.4.18。你可以看到它here。这意味着您需要在 akka-slf4j 依赖于 运行 应用程序而没有问题的情况下下降到该版本。