• 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”!!!)

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

  • 相关阅读:
    Android系统介绍与框架(转)
    6个值得推荐的Android开源框架简介(转)
    程序员最喜爱的12个Android应用开发框架二(转)
    android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
    Android数据缓存(转)
    [UI]实用案例--Shape绘制实用圆圈
    接口API测试和返回值JSON解析的插件
    Android LayoutInflater详解(转)
    一个json字符串
    Android中设定EditText的输入长度(转)
  • 原文地址:https://www.cnblogs.com/miracle-luna/p/15428031.html
Copyright © 2020-2023  润新知