Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
797 views
in Technique[技术] by (71.8m points)

java - RabbitMQ SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

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).

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

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.

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...