我有一个带有Spring AMQP的Spring应用程序。我想运行以H2数据库启动Spring的JUnit测试。
但是对于Spring AMQP,我在启动期间遇到了以下异常:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.core.AmqpAdmin]: Factory method 'amqpAdmin' threw exception; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640)
... 83 common frames omitted
Caused by: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
有什么方法可以模拟与RabbitMQ的连接?
最佳答案
RabbitMQ-mock
库可能会有所帮助,它会模拟ConnectionFactory
以便提供模拟的连接。可以在here中找到集成测试的工作示例。