SpringCloud工作笔记052---SpringCloud打包部署流程_打包时报错: BeanCreationNotAllowedException: Error creating bean w

  JAVA技术交流QQ群:170933152  

spring cloud 测试的时候报 BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration' 但能正确跑完测试方法

因为都能正确的跑测试方法,所以我也不太注意它,但是有时候闲得蛋疼就会找一下原因。

具体原因我也说不清,直接丢个连接

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

里面的一位叫crmky的大神解释的很清楚了,

由于是英文,我理解是可以的,但是翻成中文就不知道什么鬼了 

所以我直接丢解决方法

复制代码

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

复制代码

当然里面的spring人员也说了

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

翻译就是最新的版本测试的时候依然有这问题,但是正常跑的时候没有

大哥,我们虽然没说正常跑的时候没这个问题,但是我们提的问题是测试的时候有这个问题啊!!!

猛然间,中了springcloud的人员的一个程序员冷笑话...

猜你喜欢

转载自blog.csdn.net/lidew521/article/details/82828928