将 slf4j 添加到 Akka 时出现 ClassNotFoundException

ClassNotFoundException when adding slf4j to Akka

以下是我将 slf4j 添加到我的 Akka 项目时得到的错误跟踪。

.....
[DEBUG] [05/07/2019 10:12:00.959] [main] [EventStream] StandardOutLogger started
error while starting up loggers
akka.ConfigurationException: Logger specified in config can't be loaded [akka.event.slf4j.Slf4jLogger] due to [java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger]
.....
Caused by: java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger
.....
Exception in thread "main" akka.ConfigurationException: Could not start logger due to [akka.ConfigurationException: Logger specified in config can't be loaded [akka.event.slf4j.Slf4jLogger] due to [java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger]]
.....

知道如何解决这个问题吗?

这个问题可以通过将 akka-slf4j 依赖项添加到您的 Akka 项目来解决。

    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor_2.12</artifactId>
        <version>2.5.22</version>
    </dependency>
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-slf4j_2.12</artifactId>
        <version>2.5.22</version>
    </dependency>

NOTE: Make sure your akka-actor and akka-slf4j have the same versions.