经过:在单元测试的时候需要通过多线程和fegin调用兄弟部门的接口,在单测得时候类似老接口能正常返回,但是在新的接口中确提示创建eurekaClientConfigBean失败的异常,将多线程改成单线程后能正常返回,老接口在多线程环境下依然可以正常返回,让提供方检测配置文件发现是一样,没有发现问题。最后查看了调用方的配置信息,发现依然是一样,最后将测试接口封装成controller的形式通过postman调用,发现能正常返回,此时排除是接口方提供的问题。
分析原因:是因为单元测试的时候 主线程先于子线程结束,主线程结束会销毁bean容器,此时子线程用bean调用fegin接口,就出错了:解决办法可以是让主线程强制休眠等待子线程全部执行结束;
异常提示信息:
Error creating bean with name 'eurekaRibbonClientConfiguration': Unsatisfied dependency expressed through field 'clientConfig'; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaClientConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!);