Incompatible fallback instance. Fallback/fallbackFactory of type class

 

Caused by: java.lang.IllegalStateException: Incompatible fallback instance. Fallback/fallbackFactory of type class com.baicun.springcloudconsumer.springcloudconsumer.hystrix.FeignClientFallbackFactory is not assignable to interface com.baicun.springcloudconsumer.springcloudconsumer.client.FeignClient for feign client SPRINGCLOUD-PROVIDER
    at org.springframework.cloud.openfeign.HystrixTargeter.getFromContext(HystrixTargeter.java:86) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallback(HystrixTargeter.java:70) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:46) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    ... 30 common frames omitted

分析原因:

hystrix 降级我是fallbackFactory来进行处理,但是feignclient注解定义回退的类型是fallback,类型不一致导致。
@Component
public class FeignClientFallbackFactory implements FallbackFactory<FeignClient> {...}
@org.springframework.cloud.openfeign.FeignClient(value = "SPRINGCLOUD-PROVIDER",fallback = FeignClientFallbackFactory.class)
public interface FeignClient {...}

解决方案: 

将接口 @FeignClient 中,hystrix降级定义改成:

@org.springframework.cloud.openfeign.FeignClient(value = "SPRINGCLOUD-PROVIDER",fallbackFactory = FeignClientFallbackFactory.class)
public interface FeignClient {...}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值