问题描述

当我们启动服务的时候,报如下错误:

image.png

解决方式

在项目中加上如下配置类:

  1. import org.springframework.beans.factory.config.BeanDefinition;
  2. import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
  3. import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
  4. import org.springframework.stereotype.Component;
  5. import java.util.Arrays;
  6. /**
  7. * guojianfeng
  8. * BeanFactory后置处理器
  9. */
  10. @Component
  11. public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
  12. @Override
  13. public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
  14. if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
  15. BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
  16. bd.setDependsOn("eurekaAutoServiceRegistration");
  17. }
  18. }
  19. private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {
  20. return Arrays.stream(beans).allMatch(beanFactory::containsBeanDefinition);
  21. }
  22. }