spring amqp

时间:2018-02-13 17:34:48

标签: java spring rabbitmq spring-amqp

我是amqp的新手。我正在尝试运行示例应用程序,并且发送方代码正在成功运行但是侦听器代码引发了错误。请帮忙。 请在下面的链接中找到代码 - https://www.journaldev.com/11713/spring-amqp-rabbitmq-example

抛出错误 -

  

线程中的异常" main" org.springframework.beans.factory.CannotLoadBeanClassException:找不到名为' asyncListener'的bean的类[com.tp.spring.amqp.rabbit.SpringAMQPRabbitAyncListener]。在类路径资源中定义[springamqp-rabbt-listener-context.xml];嵌套异常是java.lang.ClassNotFoundException:com.tp.spring.amqp.rabbit.SpringAMQPRabbitAyncListener

我在运行SpringAMQPRabbitListenerContainer.java时遇到的错误如下所示 -

  

SLF4J:无法加载类" org.slf4j.impl.StaticLoggerBinder"。   SLF4J:默认为无操作(NOP)记录器实现SLF4J:   有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder   细节。线程" main"中的例外情况   org.springframework.context.ApplicationContextException:失败   启动bean' myListenerContainer&#39 ;;嵌套异常是   org.springframework.amqp.AmqpIllegalStateException:致命异常   听众启动时间   org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:170)     在   org.springframework.context.support.DefaultLifecycleProcessor.access $ 1(DefaultLifecycleProcessor.java:154)     在   org.springframework.context.support.DefaultLifecycleProcessor $ LifecycleGroup.start(DefaultLifecycleProcessor.java:339)     在   org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:143)     在   org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:108)     在   org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:926)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)     在   org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139)     在   org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:83)     在   com.tp.spring_amqp_rabbitmq.SpringAMQPRabbitListenerContainer.main(SpringAMQPRabbitListenerContainer.java:9)   引起:org.springframework.amqp.AmqpIllegalStateException:致命   侦听器启动时的异常   org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doStart(SimpleMessageListenerContainer.java:333)     在   org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:360)     在   org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167)     ... 9更多引起:   org.springframework.amqp.rabbit.listener.FatalListenerStartupException:   无法为侦听器准备队列。队列不存在或者   经纪人不允许我们使用它。在   org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:228)     在   org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer $ AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:516)     在java.lang.Thread.run(未知来源)引起:   java.io.IOException at   com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:124)at at   com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:120)at at   com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:142)     在   com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:996)     在   com.rabbitmq.client.impl.recovery.AutorecoveringChannel.queueDeclarePassive(AutorecoveringChannel.java:364)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.springframework.amqp.rabbit.connection.CachingConnectionFactory $ CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:348)     在com.sun.proxy。$ Proxy2.queueDeclarePassive(未知来源)at   org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:213)     ... 2更多引起:com.rabbitmq.client.ShutdownSignalException:   通道错误;协议方法:#method(reply-code = 404,   reply-text = NOT_FOUND - 没有队列' tpQueue'在vhost' /',class-id = 50,   method-id = 10)at   com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     在   com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)     在   com.rabbitmq.client.impl.AMQChannel $ BlockingRpcContinuation.getReply(AMQChannel.java:443)     在   com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:263)     在   com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:136)     ... 11更多引起:com.rabbitmq.client.ShutdownSignalException:   通道错误;协议方法:#method(reply-code = 404,   reply-text = NOT_FOUND - 没有队列' tpQueue'在vhost' /',class-id = 50,   method-id = 10)at   com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:509)at at   com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:340)at at   com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:162)     在   com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:109)     在   com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:643)     在   com.rabbitmq.client.impl.AMQConnection.access $ 300(AMQConnection.java:47)     在   com.rabbitmq.client.impl.AMQConnection $ MainLoop.run(AMQConnection.java:581)     ......还有1个

1 个答案:

答案 0 :(得分:1)

你真的应该确定类com.tp.spring.amqp.rabbit.SpringAMQPRabbitAyncListener在你的类路径上。

我理解XML配置我的误导,但在提到的com.tp.spring.amqp.rabbit包中没有该类,它确实无法正常工作。

另外注意该类在Async部分中的类型。