SLF4J: クラス「org.slf4j.impl.StaticLoggerBinder」のロードに失敗しました

1. 現象の説明

最近、RabbitMQ プログラムをデバッグしているときに、ログに次のエラーが発生しました。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

ここに画像の説明を挿入

RabbitMQ は次のように message_program コードを送信します。

package com.miracle.luna.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.nio.charset.StandardCharsets;

/**
 * @author Miracle Luna
 * @date 2021/10/19
 */
public class SendMQ {
    
    
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception{
    
    
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");

        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        String message = "Hello, RabbitMQ!";
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes(StandardCharsets.UTF_8));
        System.out.println("Send '" + message + "'");

        channel.close();
        connection.close();
    }
}

2、解決策

次のように、 pom ファイルにslf4j-simpleの依存関係を追加し、プロジェクトをリロードします。

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.7.32</version>
   <scope>compile</scope>
</dependency>

(ローカルでデバッグする場合、pom 参照のスコープの値は「test」ではなく「compile」であることに注意してください。!!!)

プログラムを再度実行すると、エラー ログはなくなり、その結果は次のようになります。
ここに画像の説明を挿入



おすすめ

転載: blog.csdn.net/aikudexiaohai/article/details/131655478