feign连续调用两个服务的坑(ribbon服务名解析错误导致404)

问题

feign同一个方法连续调用两个服务的后再次调用方法,导致ribbon服务名解析路径错误,从而返回404;

原因

在这里插入图片描述
如上图定义的myRule这个bean所在的类被@ComponentScans扫描到了,这就是问题出现的原因。。
解释:网上找了Ribbon的使用注意事项,说官网给出ribbon使用负载策略是,务必要保证ribbon的负载代码,所以上图的类不能被@ComponentScans扫描

解决办法

方法一:删除上图的那个类

方法二:
修改@ComponentScan,不扫描上图那个类(MyselfRule.class)

下面展示一些 内联代码片

@ComponentScan(value = {"com.**"}
,excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value = {MyselfRule.class})
)
@EnableFeignClients
@SpringCloudApplication
@EnableSwagger2
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

版权声明:本文为qq_28915045原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。