方案来自:https://github.com/spring-cloud/spring-cloud-netflix/issues/1952
解决办法:
1 @Component 2 public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor { 3 4 @Override 5 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 6 if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) { 7 BeanDefinition bd = beanFactory.getBeanDefinition("feignContext"); 8 bd.setDependsOn("eurekaAutoServiceRegistration"); 9 } 10 } 11 12 private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) { 13 return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b)); 14 } 15 }