zoukankan      html  css  js  c++  java
  • SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

    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>

    (注意本地调试的时候,pom引用里 scope的值是“compile”,而非“test”!!!)

    再次运行程序,就不会有报错日志了,效果如下:

  • 相关阅读:
    100 numpy exercises
    IndentationError: unindent does not match any outer indentation level
    Git详解之七:自定义Git
    Git详解之六:Git工具
    Git详解之五:分布式Git
    Git详解之四:服务器上的Git
    Git详解之三:Git分支
    Git详解之二:Git基础
    Git详解之一:Git起步
    Jquery基础之事件操作
  • 原文地址:https://www.cnblogs.com/miracle-luna/p/15428031.html
Copyright © 2011-2022 走看看