异常信息

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:216)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:283)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:991)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
    at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:556)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.dx.asst.customer.AsstCustomerApplication.main(AsstCustomerApplication.java:21)

2017-11-14 12:45:53.166  INFO [bootstrap,,,] 67268 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
2017-11-14 12:45:53.169  INFO [bootstrap,,,] 67268 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-11-14 12:45:53.203  INFO [bootstrap,,,] 67268 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-14 12:45:53.411 ERROR [bootstrap,,,] 67268 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'SYNC_XGT_USER_UPDATED' that could not be found.


Action:

Consider defining a bean named 'SYNC_XGT_USER_UPDATED' in your configuration.

问题分析

其实这个错误就是没有配置@EnableBinding(value = { XXXProcessor.class }),而却在监听类上配置了@StreamListener(“SYNC_XGT_USER_UPDATED”)导致的,错误比较低级,但是介于spring cloud stream网上资料较少,就把错误粘贴出来,也许能帮到你

使用spring cloud stream配置注意事项

这里注意的是使用spring cloud stream 时一定要注意三处配置:

  1. 定义Channel接口时,注意@Input标记下的方法返回值是SubscribableChannel类用来接收消息渠道定义,@Output标记的方法下返回值MessageChannel类用户生产消息,定义好后需要使用@EnableBinding(value={xxx.class})配置开启。
  2. 在application.yml(当然你可以是.properties文件)配置你的channel,其实这里对于rabbitmq来说即使是在配置Bind,其下一般配置三个参数destination、group、content-type 对于rabbitmq,destination就是交换机名称,group就是队列(队列名字会变成destination+group的值),content-type用来指定数据交互的格式类型了,如果你想配置使用路由配置

    spring:cloud:stream:rabbit: bindings:你的消息接收的Channel名字: consumer:bindingRoutingKey:路由值
  3. 定义你的监听类,在方法上使用@StreamListener(“你的消息接收的Channel名字”),在监听类上加上@Component注解

好了,就先说这么多,后面我们会写单独的连载文章介绍关于spring cloud stream rabbitMq的使用,如果你在使用spring cloud stream rabbit时有什么不清楚,可以留言或加关注私聊我,很愿意为你解答。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐