I had a problem with FallbackFactory and FeignClient when using feign.circuitbreaker.enabled=true option with feign.hystrix.FallbackFactory together.

IllegalStateException
Incompatible fallbackFactory instance. Fallback/fallbackFactory of type class cloud.in.action.proxy.BServiceFeinClient$BServiceFallbackFactory is not assignable to interface org.springframework.cloud.openfeign.FallbackFactory for feign client b-service

When using feign.circuitbreaker.enabled=true, FeignCircuitBreakerTargeter checks that beanType overrides org.springframework.cloud.openfeign.FallbackFactory.

FeignCircuitBreakerTargeter class
  • targetType = interface org.springframework.cloud.openfeign.FallbackFactory
  • beanType = my fallbackFactory
    private <T> T getFromContext(String fallbackMechanism, String feignClientName,
            FeignContext context, Class<?> beanType, Class<T> targetType) {
        Object fallbackInstance = context.getInstance(feignClientName, beanType);
        if (fallbackInstance == null) {
            throw new IllegalStateException(String.format(
                    "No " + fallbackMechanism
                            + " instance of type %s found for feign client %s",
                    beanType, feignClientName));
        }

        if (!targetType.isAssignableFrom(beanType)) {
            throw new IllegalStateException(String.format("Incompatible "
                    + fallbackMechanism
                    + " instance. Fallback/fallbackFactory of type %s is not assignable to %s for feign client %s",
                    beanType, targetType, feignClientName));
        }
        return (T) fallbackInstance;
    }

Here this is questions. 1. What is difference between feign.circuitbreaker.enabled option and feign.hystrix.enabled option ? Is it just using FeignCircuitBreakerTargeter class or not? 2. Why does it strictly check class type when using feign.circuitbreaker.enabled?

  • When using option feign.circuitbreaker.enabled=true

    • import feign.hystrix.FallbackFactory = error occur
    • import org.springframework.cloud.openfeign.FallbackFactory = no problem
  • When using option feign.hystrix.enabled=true

    • import feign.hystrix.FallbackFactory = no problem
    • import org.springframework.cloud.openfeign.FallbackFactory = no problem

Thanks.

Comment From: ryanjbaxter

feign.circuitbreaker.* is for enabling support for Spring Cloud CircuitBreaker. It does not use Hystrix. You should use Spring Cloud CircuitBreaker as Hystrix is removed in the 2020.0.x release.

https://docs.spring.io/spring-cloud-openfeign/docs/2.2.7.RELEASE/reference/html/#spring-cloud-feign-circuitbreaker

Comment From: Junhyunny

thanks