2017-06-17 67 views
0

我有一個工作akka-http應用程序。現在我嘗試通過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驅逐警告。與上面相同的問題:如何找出要使用的版本?

回答

2

不幸的是akka-httpakka的其餘部分分開版本化,最新版本不一定使用最新版本akka。在akka-http版本10.0.7的情況下,兼容的akka版本是2.4.18。你可以看到它here。這意味着您需要在akka-slf4j依賴關係中下降到該版本以運行應用程序,而不會出現問題。

相關問題