当前位置:   article > 正文

SpringBoot集成rabbitmq错误:org.springframework.amqp.AmqpConnectException: java.net.ConnectException的解决办法_java: 无法访问org.springframework.amqp.rabbit.core.rab

java: 无法访问org.springframework.amqp.rabbit.core.rabbittemplate 错误的类文

在集成rabbitmq后,运行项目,报错日志:

  1. org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
  2. at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62)
  3. at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:376)
  4. at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573)
  5. at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1436)
  6. at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1417)
  7. at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:712)
  8. at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:780)
  9. at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:776)
  10. at com.wangsf.amqp.Spring02AmqpApplicationTests.contextLoads(Spring02AmqpApplicationTests.java:34)
  11. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  12. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  13. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  14. at java.lang.reflect.Method.invoke(Method.java:498)
  15. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  16. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  17. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  18. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  19. at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
  20. at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
  21. at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
  22. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  23. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
  24. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
  25. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  26. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  27. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  28. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  29. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  30. at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  31. at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
  32. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  33. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
  34. at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  35. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  36. at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  37. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  38. at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  39. Caused by: java.net.ConnectException: Connection refused: connect
  40. at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
  41. at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
  42. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  43. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  44. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  45. at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
  46. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  47. at java.net.Socket.connect(Socket.java:589)
  48. at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50)
  49. at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907)
  50. at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
  51. at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799)
  52. at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:356)
  53. ... 35 more

配置文件:

  1. spring.rabbitmq.host=192.168.220.128
  2. spring.rabbitmq.username=guest
  3. spring.rabbitmq.password=guest
  4. #spring.rabbitmq.port=5672
  5. #spring.rabbitmq.virtual-host=

注意:用户使用的是guest,而guest只能默认只能连接本机IP(也就是127.0.0.1),而192.168.220.128是虚拟机的ip,所以会报org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect

解决方法:就是修改rabbitmq的配置文件rabbitmq.config 增加一行代码

1、进入rabbitmq的安装目录(视个人情况而定)

2、编辑abbitmq.config配置文件

3、增加如下代码

[{rabbit,[{loopback_users,[]}]}]

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/1018443
推荐阅读
相关标签
  

闽ICP备14008679号