为什么我不能加载org.slf4j.impl.StaticLoggerBinder类 [英] Why can't I load class org.slf4j.impl.StaticLoggerBinder

查看:148
本文介绍了为什么我不能加载org.slf4j.impl.StaticLoggerBinder类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Akka上一个视频课程,但无法正常运行日志记录.我使用IntelliJ.我已经尝试了不同版本的slf4j ...,我有pom.xml

I'm following a video course in Akka, and can't get the logging to work. I use IntelliJ. I have tried a little with different versions of slf4j... and I have the pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>AkkaPrime2</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <akka.version>2.6.8</akka.version>
    <scala.version>2.13</scala.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor-typed_2.13</artifactId>
        <version>${akka.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor-testkit-typed -->
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor-testkit-typed_2.13</artifactId>
        <version>${akka.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
</dependencies>
</project>

并且代码正在使用正常" Akka方法.

And the code is using "normal" akka methods.

代码运行后:

.onAnyMessage(message ->{
  System.out.println("I received the message : " + message);
  return this;
})

可以,但是我可以

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation

(和日志消息)

之后将执行此代码

.onMessageEquals("create a child", () -> {
  ActorRef<String> secondActor = getContext().spawn(FirstSimpleBehavior.create(),"second actor");
  secondActor.tell("who are you");
  return this;
})

但是控制台显示:

SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.

推荐答案

我发现方法 spawn()不接受我的第二个参数,因为它包含一个空格(我错过了那个在视频中).在途中发现Logback已包含slf4j(链接),以便( slf4j)我从pom中移除了.

I found that the method spawn() didn't accept my second argument, because it contained a space (I had missed that in the video). On the way a found that Logback already included slf4j (link) so that (slf4j) I removed from the pom.

我摆弄着pom,所以现在logback的版本改变了...但是pom现在是:

I fiddled with the pom so now the version of logback changed... But the pom is now:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>AkkaPrime2</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <akka.version>2.6.8</akka.version>
    <scala.version>2.13</scala.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor-typed_2.13</artifactId>
        <version>${akka.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor-testkit-typed -->
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor-testkit-typed_2.13</artifactId>
        <version>${akka.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.9</version>
        <!--scope>test</scope-->
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>
</project>

在baeldung.com上,没有范围"标签,所以我不使用(我也不知道为什么要使用它).

At baeldung.com there was no "scope" tag so I don't use (I don't know why to use it either).

这篇关于为什么我不能加载org.slf4j.impl.StaticLoggerBinder类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆