欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

解决SpringMVC项目连接RabbitMQ出错的问题

程序员文章站 2022-06-25 14:50:30
在第一次启动项目的时候,由于使用了rabbitmq的默认guest账号,怎么也登不进去,后来还是在admin重新创建了一个其他的账号,然后开启所有的权限,最后在配置文件中修改了账号,这样才成功连接ra...

在第一次启动项目的时候,由于使用了rabbitmq的默认guest账号,怎么也登不进去,后来还是在admin重新创建了一个其他的账号,然后开启所有的权限,最后在配置文件中修改了账号,这样才成功连接rabbitmq。

但是到今天重新启动项目的时候,想试试guest账号还行不行,尝试了一次,居然可以重新启动了,吃惊!

在此记录,以防今后忘记。

补充:解决rabbitmq无法连接导致的错误

最近学写项目的时候用到rabbitmq始终无法连接,踩了挺多坑的,希望分享出来,让大家少踩一些. 错误提示是这样的:

org.springframework.amqp.amqpioexception: java.io.ioexception
at org.springframework.amqp.rabbit.support.rabbitexceptiontranslator.convertrabbitaccessexception(rabbitexceptiontranslator.java:71) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.createbareconnection(abstractconnectionfactory.java:476) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.connection.cachingconnectionfactory.createconnection(cachingconnectionfactory.java:614) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.connection.connectionfactoryutils.createconnection(connectionfactoryutils.java:240) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.core.rabbittemplate.doexecute(rabbittemplate.java:1797) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:1771) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:1752) ~[spring-rabbit-2.0.3.release.jar:2.0.3.release]
at org.springframework.boot.actuate.amqp.rabbithealthindicator.getversion(rabbithealthindicator.java:48) ~[spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.amqp.rabbithealthindicator.dohealthcheck(rabbithealthindicator.java:44) ~[spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.health.abstracthealthindicator.health(abstracthealthindicator.java:84) ~[spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.health.compositehealthindicator.health(compositehealthindicator.java:68) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.health.healthendpoint.health(healthendpoint.java:47) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.8.0_202]
at sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:1.8.0_202]
at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.method.invoke(method.java:498) ~[na:1.8.0_202]
at org.springframework.util.reflectionutils.invokemethod(reflectionutils.java:223) [spring-core-5.0.6.release.jar:5.0.6.release]
at org.springframework.boot.actuate.endpoint.invoke.reflect.reflectiveoperationinvoker.invoke(reflectiveoperationinvoker.java:76) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.endpoint.annotation.abstractdiscoveredoperation.invoke(abstractdiscoveredoperation.java:61) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.endpoint.jmx.endpointmbean.invoke(endpointmbean.java:104) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at org.springframework.boot.actuate.endpoint.jmx.endpointmbean.invoke(endpointmbean.java:93) [spring-boot-actuator-2.0.2.release.jar:2.0.2.release]
at com.sun.jmx.interceptor.defaultmbeanserverinterceptor.invoke(defaultmbeanserverinterceptor.java:819) [na:1.8.0_202]
at com.sun.jmx.mbeanserver.jmxmbeanserver.invoke(jmxmbeanserver.java:801) [na:1.8.0_202]
at javax.management.remote.rmi.rmiconnectionimpl.dooperation(rmiconnectionimpl.java:1468) [na:1.8.0_202]
at javax.management.remote.rmi.rmiconnectionimpl.access300 ( r m i c o n n e c t i o n i m p l . j a v a : 76 ) [ n a : 1.8. 0 2 02 ] a t j a v a x . m a n a g e m e n t . r e m o t e . r m i . r m i c o n n e c t i o n i m p l 300(rmiconnectionimpl.java:76) [na:1.8.0_202] at javax.management.remote.rmi.rmiconnectionimpl300(rmiconnectionimpl.java:76)[na:1.8.0 
2
​ 
 02]atjavax.management.remote.rmi.rmiconnectionimplprivilegedoperation.run(rmiconnectionimpl.java:1309) [na:1.8.0_202]
at javax.management.remote.rmi.rmiconnectionimpl.doprivilegedoperation(rmiconnectionimpl.java:1401) [na:1.8.0_202]
at javax.management.remote.rmi.rmiconnectionimpl.invoke(rmiconnectionimpl.java:829) [na:1.8.0_202]
at sun.reflect.generatedmethodaccessor112.invoke(unknown source) ~[na:na]
at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.method.invoke(method.java:498) ~[na:1.8.0_202]
at sun.rmi.server.unicastserverref.dispatch(unicastserverref.java:357) [na:1.8.0_202]
at sun.rmi.transport.transport$1.run(transport.java:200) [na:1.8.0_202]
at sun.rmi.transport.transport1. r u n ( t r a n s p o r t . j a v a : 197 ) [ n a : 1.8. 0 2 02 ] a t j a v a . s e c u r i t y . a c c e s s c o n t r o l l e r . d o p r i v i l e g e d ( n a t i v e m e t h o d ) [ n a : 1.8. 0 2 02 ] a t s u n . r m i . t r a n s p o r t . t r a n s p o r t . s e r v i c e c a l l ( t r a n s p o r t . j a v a : 196 ) [ n a : 1.8. 0 2 02 ] a t s u n . r m i . t r a n s p o r t . t c p . t c p t r a n s p o r t . h a n d l e m e s s a g e s ( t c p t r a n s p o r t . j a v a : 573 ) [ n a : 1.8. 0 2 02 ] a t s u n . r m i . t r a n s p o r t . t c p . t c p t r a n s p o r t 1.run(transport.java:197) [na:1.8.0_202] at java.security.accesscontroller.doprivileged(native method) [na:1.8.0_202] at sun.rmi.transport.transport.servicecall(transport.java:196) [na:1.8.0_202] at sun.rmi.transport.tcp.tcptransport.handlemessages(tcptransport.java:573) [na:1.8.0_202] at sun.rmi.transport.tcp.tcptransport1.run(transport.java:197)[na:1.8.0 
2
​ 
 02]atjava.security.accesscontroller.doprivileged(nativemethod)[na:1.8.0 
2
​ 
 02]atsun.rmi.transport.transport.servicecall(transport.java:196)[na:1.8.0 
2
​ 
 02]atsun.rmi.transport.tcp.tcptransport.handlemessages(tcptransport.java:573)[na:1.8.0 
2
​ 
 02]atsun.rmi.transport.tcp.tcptransportconnectionhandler.run0(tcptransport.java:834) [na:1.8.0_202]
at sun.rmi.transport.tcp.tcptransportc o n n e c t i o n h a n d l e r . l a m b d a connectionhandler.lambdaconnectionhandler.lambdarun0 ( t c p t r a n s p o r t . j a v a : 688 ) [ n a : 1.8. 0 2 02 ] a t j a v a . s e c u r i t y . a c c e s s c o n t r o l l e r . d o p r i v i l e g e d ( n a t i v e m e t h o d ) [ n a : 1.8. 0 2 02 ] a t s u n . r m i . t r a n s p o r t . t c p . t c p t r a n s p o r t 0(tcptransport.java:688) [na:1.8.0_202] at java.security.accesscontroller.doprivileged(native method) [na:1.8.0_202] at sun.rmi.transport.tcp.tcptransport0(tcptransport.java:688)[na:1.8.0 
2
​ 
 02]atjava.security.accesscontroller.doprivileged(nativemethod)[na:1.8.0 
2
​ 
 02]atsun.rmi.transport.tcp.tcptransportconnectionhandler.run(tcptransport.java:687) [na:1.8.0_202]
at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1149) ~[na:1.8.0_202]
at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:624) ~[na:1.8.0_202]
at java.lang.thread.run(thread.java:748) ~[na:1.8.0_202]

这是因为我们并没有创建出用户

首先打开rabbitmq界面add user 创建用户

解决SpringMVC项目连接RabbitMQ出错的问题

有了用户之后是no access

解决SpringMVC项目连接RabbitMQ出错的问题

点击右边的virtual hosts 咱们新建一个virtual host

解决SpringMVC项目连接RabbitMQ出错的问题

如图 我们设置user 然后set permission

这里我们直接设置为超级管理员了

(权限分为超级管理原,监控者,policymaker,普通管理员和只能产生生产者和消费者普通用户)

当发现current permissions有了你的权限再尝试连接就ok拉~

解决SpringMVC项目连接RabbitMQ出错的问题

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。