1. 程式人生 > >SpringCloud工作筆記052---SpringCloud打包部署流程_打包時報錯: BeanCreationNotAllowedException: Error creating bean w

SpringCloud工作筆記052---SpringCloud打包部署流程_打包時報錯: BeanCreationNotAllowedException: Error creating bean w

因為都能正確的跑測試方法,所以我也不太注意它,但是有時候閒得蛋疼就會找一下原因。

具體原因我也說不清,直接丟個連線

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的人員的一個程式設計師冷笑話...