美文网首页
spring-cloud feginClient unit te

spring-cloud feginClient unit te

作者: zebei | 来源:发表于2018-10-11 12:53 被阅读0次

最近单元测试时碰到需要mock feginClient的接口

因为项目中存在fegin的hystrix,在mock的时候会装在其中一个bean , cloud中的fegin是接口而hystrix又是接口的实现,所以在测试的时候会报错:


java.lang.IllegalStateException: Unable to register mock bean ..* expected a single matching bean to replace but found [..client,..clientHystrix]


其实测试启动@mockbean会使用自己装载的bean替换项目中的 找到了两个类似实体会失败。

解决:

在hystrix中增加@Profile("!test")对测试时忽略装载的状态

在test Class中加入@ActiveProfiles("test")  保证hystrix在测试时不会被检测装载 也就不会和相应的Fegin发生冲突

相关文章

网友评论

      本文标题:spring-cloud feginClient unit te

      本文链接:https://www.haomeiwen.com/subject/jahbaftx.html