1、報(bào)錯(cuò)信息:
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、報(bào)錯(cuò)原因:
根本原因是關(guān)閉 ApplicationContext 時(shí), 它將銷毀所有單例 bean, eurekaAutoServiceRegistration 首先銷毀, 然后銷毀feignContext. 銷毀 feignContext 時(shí), 它將關(guān)閉與每個(gè) FeignClient 關(guān)聯(lián)的 ApplicationContext. 由于eurekaAutoServiceRegistration 監(jiān)聽 ContextClosedEvent, 因此這些事件將發(fā)送到該bean. 不幸的是, 由于它已被銷毀, 因此我們得到了上述異常(嘗試在銷毀中創(chuàng)建 bean )文章來源地址http://www.zghlxwxcb.cn/news/detail-548105.html
3、解決方案:
@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
/* 調(diào)整依賴順序,這樣會先銷毀 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));
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-548105.html
到了這里,關(guān)于tomcat版本升級-啟動報(bào)錯(cuò)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!