1、报错信息:
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!)
2、报错原因:
根本原因是关闭 ApplicationContext 时, 它将销毁所有单例 bean, eurekaAutoServiceRegistration 首先销毁, 然后销毁feignContext. 销毁 feignContext 时, 它将关闭与每个 FeignClient 关联的 ApplicationContext. 由于eurekaAutoServiceRegistration 监听 ContextClosedEvent, 因此这些事件将发送到该bean. 不幸的是, 由于它已被销毁, 因此我们得到了上述异常(尝试在销毁中创建 bean )文章来源地址https://www.toymoban.com/news/detail-548105.html
3、解决方案:
@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
/* 调整依赖顺序,这样会先销毁 feignContext, 再销毁 eurekaAutoServiceRegistration */
BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaAutoServiceRegistration");
}
}
private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {
return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b));
}
}
文章来源:https://www.toymoban.com/news/detail-548105.html
到了这里,关于tomcat版本升级-启动报错的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!