エラーが表示されました.BeanCreationNotAllowedException:Error creating bean with name'eurekaAutoServiceRegistration'
6933 ワード
問題
具体的にどういうわけか知りたいのは、
The root cause is when closing ApplicationContext, it will destroy all singleton bean, eurekaAutoServiceRegistration is destroyed first, then feignContext. When destroy feignContext, it will close the ApplicationContext associated with each FeignClient. Since eurekaAutoServiceRegistration listen on ContextClosedEvent, those events will be sent to that bean. Unfortunately because it has been destroyed, so we got the above exception (try to create bean in destruction).
ここで簡単に言えば
1.
2.ただし、
3.同時に
4.解決策は括弧の中にあり、再破棄時に
qq群
BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration'
のように、ここで直接解決策を提供し、直接次のようなものを追加すればよい.
package com.newcoin.broker.web.manager.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
import java.util.Arrays;
/**
* @Description
* @Author apdoer
* @Date 2019/7/14 20:53
* @Version 1.0
*/
@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
if (containsBeanDefinition(configurableListableBeanFactory,"feignContext","eurekaAutoServiceRegistration")){
BeanDefinition bd = configurableListableBeanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaAutoServiceRegistration");
}
}
private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {
return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b));
}
}
具体的にどういうわけか知りたいのは、
springcloud
公式のissue
https://github.com/spring-cloud/spring-cloud-netflix/issues/1952
中crmky
の回答The root cause is when closing ApplicationContext, it will destroy all singleton bean, eurekaAutoServiceRegistration is destroyed first, then feignContext. When destroy feignContext, it will close the ApplicationContext associated with each FeignClient. Since eurekaAutoServiceRegistration listen on ContextClosedEvent, those events will be sent to that bean. Unfortunately because it has been destroyed, so we got the above exception (try to create bean in destruction).
ここで簡単に言えば
1.
ApplicationContext
容器を閉鎖すると、すべての単例bean
が廃棄され、eurekaAutoServiceRegistration
が最初に廃棄され、その後がfeignContext
である.2.ただし、
feignContext
を閉じると、FeignClient
に関連付けられたApplicationContext
はすべて破棄される3.同時に
eurekaAutoServiceRegistration
がContextClosedEvent
ContextClosedEvent
を傍受するすべてのイベントがそのbean
に送信されます.残念なことに、それはすでに閉鎖されているので、上の異常が発生します.4.解決策は括弧の中にあり、再破棄時に
bean
を作成するqq群
859759121
に参加することを歓迎して、大量の無料vip学習資源、いっしょに成長して、いっしょに進歩します