我正在尝试使用一个简单的RabbitMQ示例,它给了我:
“线程中的异常”主“java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory”。
我的构建路径上有amqp-client-4.0.2.jar,slf4j-1.7.25.zip,slf4j-jdk14.jar.zip和log4j-1.2.15.jar。
我的代码非常基础,我从这里尝试了很多关于simillar问题的建议,我改变了不同类型的slfj,但它仍然不起作用。
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST);
factory.setUsername(USER);
factory.setPassword(TOKEN);
factory.setVirtualHost(VHOST);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
String message = "Test!";
channel.basicPublish(EXCHANGE_NAME, QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "' with id=");
channel.close();
connection.close();
完整错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.rabbitmq.client.impl.AMQConnection.<clinit>(AMQConnection.java:49)
at com.rabbitmq.client.ConnectionFactory.<init>(ConnectionFactory.java:91)
at ro.test.RMQ_Send_LocalHost.main(RMQ_Send_LocalHost.java:20)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more"
答案 0 :(得分:0)
尝试将slf4j-api依赖项添加到您的应用程序中: