新建一个配置类
package com.cloud.client.user.feign; 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; @Component public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (containsBeanDefinition(beanFactory, "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://blog.csdn.net/yudianxiaoxiao/article/details/93674293