Describe the bug spring-cloud-starter-openfeign:4.0.0

Sample org.springframework.cloud.context.named.NamedContextFactory#getInstance(java.lang.String, java.lang.Class)


    @Test
    public void getBeanByType() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(Fallback.class);

        context.refresh();

        Object bean = context.getBean(Fallback.class);
        System.out.println(bean);

        System.out.println(context.getBean("fallback"));
    }

    @Component("fallback")
    public static class Fallback implements FactoryBean<String> {

        @Override
        public String getObject() throws Exception {
            return "getObject return";
        }

        @Override
        public Class<?> getObjectType() {
            return String.class;
        }
    }

Comment From: min1854

Spring Cloud Openfeign fallback is FactoryBean , IllegalStateException

Spring Cloud Openfeign fallback is FactoryBean , IllegalStateException

Caused by: java.lang.IllegalStateException: Incompatible fallback instance. Fallback/fallbackFactory of type class com.old.common.feign.fallback.FallbackTemplate is not assignable to interface com.old.common.api.weChat.feign.test.TestFeign for feign client com.old.common.api.weChat.feign.test.TestFeign at org.springframework.cloud.openfeign.FeignCircuitBreakerTargeter.getFromContext(FeignCircuitBreakerTargeter.java:82) at org.springframework.cloud.openfeign.FeignCircuitBreakerTargeter.targetWithFallback(FeignCircuitBreakerTargeter.java:68) at org.springframework.cloud.openfeign.FeignCircuitBreakerTargeter.target(FeignCircuitBreakerTargeter.java:50) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:470) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:421) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:148) ... 87 more

Comment From: min1854

fallback is FactoryBean IllegalStateException

Comment From: OlgaMaciaszek

As the Javadoc of the FactoryBean says NB: A bean that implements this interface cannot be used as a normal bean., and as documented in @FeignClient Javadoc for the fallback argument, he fallback class must implement the interface annotated by this annotation and be a valid spring bean.. This is not a scenario that we support. What is your use case and why do you intend to use a FactoryBean for fallback?

Comment From: min1854

As the Javadoc of the says , and as documented in Javadoc for the argument, . This is not a scenario that we support. What is your use case and why do you intend to use a for fallback?FactoryBean``NB: A bean that implements this interface cannot be used as a normal bean.``@FeignClient``fallback``he fallback class must implement the interface annotated by this annotation and be a valid spring bean.``FactoryBean

I want to create one fallbackTemplate, And the instance returned by FactoryBean.getObject is the implementation instance of feignclien