beanFactory创建失败-application-mq.xml配置文件问题

本文通过一个具体的bug案例,分析了配置项依赖网络时可能遇到的问题,并提供了详细的解决方案。首先展示了出现问题时的bug截图,接着深入探讨了问题代码及其背后的成因,最后给出了切实可行的解决办法。

一:bug截图

二:原因分析
1:问题代码

2:原因分析
1:该段配置需要网路

三:解决方案


14:06:01.565 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - [refresh,599] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productInformationController': Unsatisfied dependency expressed through field 'productInformationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productInformationServiceImpl': Unsatisfied dependency expressed through field 'rabbitMqService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.aerors.common.mq.service.RabbitMqService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 14:06:01.570 [main] WARN o.s.c.a.AnnotationConfigApplicationContext - [doClose,1075] - Exception thrown from ApplicationListener handling ContextClosedEvent org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'rabbitConnectionFactory': 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:220) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:214) at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:264) at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:221) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:140) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:430) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:436) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:387) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1072) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1035) at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:99) at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:213) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1163) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1156) at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1123) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:604) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289) at com.aerors.interpretation.AerorsInterpretationApplication.main(AerorsInterpretationApplication.java:20) 14:06:01.572 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,215] - dynamic-datasource start closing .... 14:06:01.574 [main] INFO c.a.d.p.DruidDataSource - [close,2204] - {dataSource-1} closing ... 14:06:01.577 [main] INFO c.a.d.p.DruidDataSource - [close,2277] - {dataSource-1} closed 14:06:01.577 [main] INFO c.b.d.d.d.DefaultDataSourceDestroyer - [destroy,98] - dynamic-datasource close the datasource named [master] success, 14:06:01.577 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,219] - dynamic-datasource all closed success,bye 14:06:01.578 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat] 14:06:01.629 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - [report,40] - *************************** APPLICATION FAILED TO START *************************** Description: Field rabbitMqService in com.aerors.interpretation.service.impl.ProductInformationServiceImpl required a bean of type 'com.aerors.common.mq.service.RabbitMqService' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.aerors.common.mq.service.RabbitMqService' in your configuration.
最新发布
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值