BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration' is reported during the spring cloud test, but the test method can be run correctly

Because I can run the test method correctly, I don't pay much attention to it, but sometimes I will find the reason when I have a lot of spare time.

I can't tell the specific reason, just drop the connection

https://github.com/spring-cloud/spring-cloud-netflix/issues/1952

One of the great gods named crmky explained it very clearly,

Since it's in English, I can understand it, but I don't know what the hell is when I translate it into Chinese.

 

So I just throw away the solution

@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));
    }
}

 

Of course, the spring staff inside also said

The workaround works when running the application, but not when running tests disappointed

The translation is the latest version when the test still has this problem, but not when running normally

 

Brother, although we did not say that there is no such problem during normal running, the problem we raised is that there is this problem during testing! ! !

Suddenly, a programmer who fell into the springcloud staff made a bad joke...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324936429&siteId=291194637