解决SpringMVC项目连接RabbitMQ出错的问题
在第一次启动项目的时候,由于使用了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 创建用户
有了用户之后是no access
点击右边的virtual hosts 咱们新建一个virtual host
如图 我们设置User 然后Set Permission
这里我们直接设置为超级管理员了
(权限分为超级管理原,监控者,policymaker,普通管理员和只能产生生产者和消费者普通用户)
当发现current permissions有了你的权限再尝试连接就ok拉~
以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。如有错误或未考虑完全的地方,望不吝赐教。
赞 (0)