SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
阿新 • • 發佈:2021-10-20
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
現象說明
最近在除錯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 傳送訊息_程式程式碼如下:
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();
}
}
解決方案
在pom檔案中增加 slf4j-simple 的依賴,並 Reload project,如下:
<!-- 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>
再次執行程式,就不會有報錯日誌了,效果如下: