tomcat部署多工程Singleton bean creation not allowed while the singletons of this factory are in destructi

本文解决了一个关于在同一个Tomcat服务器下部署多个Java应用时出现的异常问题。该问题源于不同应用创建了相同的单例对象,导致启动失败。通过在各应用的web.xml文件中配置不同的webAppRootKey参数来区分它们,从而避免了冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

场景:同一个tomcat下部署多个java工程。

问题现象: 启动tomcat时报异常Singleton bean creation not allowed while the singletons of this factory are in destruction

问题原因:不同的工程分别创建了同一个单例。

处理方案:1、在应用的web.xml文件中,配置不同的webAppRootKey,<param-value>值可以自定义,只要相同tomcat下的各个工程保持不同即可。

  1. <context-param>  
  2.   <param-name>webAppRootKey</param-name>  
  3.   <param-value>web.sample.root</param-value>  
  4. </context-param>  

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、付费专栏及课程。

余额充值