本文介绍了RabbitMQ SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 InteliJ IDEA (Maven 3.3.9) 在 Java 中连接到 RabbitMQ,但是在执行所需步骤时发生错误(在连接到 RabbitMQ 之前创建 ConnectionFactory 对象).

I'm trying to connect to RabbitMQ in Java with InteliJ IDEA (Maven 3.3.9), but an error occurs when doing the required step (creating ConnectionFactory object before connecting to RabbitMQ).

有关详细信息:Maven 本身安装了 amqp-client:5.7.2org.slf4j-api:1.7.26.

For detailed information: Maven itself installs amqp-client:5.7.2 and org.slf4j-api:1.7.26.

我在这里错过了什么?我试图导入 org.slf4j.impl.StaticLoggerBinder,但 Java 本身不知道这个.

What am I missing here? I tried to import org.slf4j.impl.StaticLoggerBinder, but Java itself doesn't know this one.

package TestPackage;

import Configuration.RabbitMQConf;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class TestingClass {
    static ConnectionFactory rbmqFactory;
    static Connection rbmqConn;
    static Channel rbmqChannel;

    public static void main(String[] args){
        RabbitMQConf rbmqConf = new RabbitMQConf();


        rbmqFactory = new ConnectionFactory();
        rbmqFactory.setUsername(rbmqConf.username);
        rbmqFactory.setPassword(rbmqConf.password);
        rbmqFactory.setVirtualHost(rbmqConf.virtualHost);
        rbmqFactory.setHost(rbmqConf.host);
        rbmqFactory.setPort(rbmqConf.port);
    }
}

我尝试运行此程序并收到此错误:

I tried to run this and got this error:

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.

这是我的 pom.xml 文件:

here's my pom.xml file :

<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>XXXX</groupId>
  <artifactId>XXXX</artifactId>
  <version>1.0-XXXX</version>

  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.rabbitmq</groupId>
      <artifactId>amqp-client</artifactId>
      <version>5.7.2</version>
    </dependency>
  </dependencies>
</project>

推荐答案

链接中的错误 几乎解释了问题所在以及如何解决它.您只需要在 pom.xml 中的依赖项中添加日志记录实现之一.

The link in the error pretty much explains what's the problem and how to fix it. You just need to add one of the logging implementations to the dependencies in pom.xml.

当org.slf4j.impl.StaticLoggerBinder 类无法加载到记忆.当找不到合适的 SLF4J 绑定时会发生这种情况在课堂路径上.放置一个(并且只有一个)slf4j-nop.jarslf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar 或类路径上的 logback-classic.jar 应该可以解决问题.

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>

这篇关于RabbitMQ SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:55