创建名称为“ rabbitListenerContainerFactory”的豆时出错

时间:2018-12-13 15:45:50

标签: spring-boot rabbitmq spring-cloud zipkin

我有一个春季启动微服务:Zuul-api-gateway-server,并且我正在尝试实现一个Zipkin服务器,以侦听Rabbitmq在微服务中记录消息。

我已将此微服务添加以下依赖项:

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth-zipkin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.amqp</groupId>
        <artifactId>spring-rabbit</artifactId>
    </dependency>

我已经使用以下命令启动了Zipkin服务器:

SET RABBIT_URI = amqp:// localhost java -jar zipkin.jar

然后我尝试启动微服务,但是出现以下错误:

  

org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / amqp / RabbitAnnotationDrivenConfiguration.class]中创建名称为'rabbitListenerContainerFactory'的bean时出错。嵌套的异常是java.lang.NullPointerException       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)〜[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在com.shopping.sandbox.netflixzuulapigatewayserver.NetflixZuulApiGatewayServerApplication.main(NetflixZuulApiGatewayServerApplication.java:16)[classes /:na]       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_171]       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_171]       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_171]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_171]       在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)上[spring-boot-devtools-2.1.1.RELEASE.jar:2.1.1.RELEASE]   引起原因:java.lang.NullPointerException:null       在org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory.getAdviceChain(AbstractRabbitListenerContainerFactory.java:198)〜[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]       在brave.spring.rabbit.SpringRabbitTracing.decorateSimpleRabbitListenerContainerFactory(SpringRabbitTracing.java:170)〜[brave-instrumentation-spring-rabbit-5.4.4.jar:na]       在org.springframework.cloud.sleuth.instrument.messaging.SleuthRabbitBeanPostProcessor.postProcessBeforeInitialization(TraceMessagingAutoConfiguration.java:186)〜[spring-cloud-sleuth-core-2.1.0.M2.jar:2.1.0.M2]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1737)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       ...省略了20个常见框架

4 个答案:

答案 0 :(得分:1)

由于Spring AMQP中存在一个错误,该错误将在2.1.3版中修复 Issue link

对于临时修复,您可以启用重试属性来创建建议链。

spring.rabbitmq.listener.direct.retry.enabled=true
spring.rabbitmq.listener.simple.retry.enabled=true

希望这可以解决您的问题。

答案 1 :(得分:0)

我遇到了同样的问题,将Spring Boot版本更改为2.1.0.RELEASE帮了我大忙。您也应该尝试。 Spring Boot版本2.1.1.RELEASE中的RabbitMQ一定有问题。

答案 2 :(得分:0)

添加build.gradle

  

应用插件:“ org.springframework.boot”

springBootVersion = 2.1.3.RELEASE springCloudVersion =格林尼治。发布

答案 3 :(得分:0)

请更换

<dependency>
   <groupId>org.springframework.amqp</groupId>
   <artifactId>spring-rabbit</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

没问题