{"record":{"id":"7b693852786c02a7","repo":"alibaba/spring-cloud-alibaba","slug":"no-s-instance-of-type-s-found-for-feign-client","errorCode":null,"errorMessage":"No %s instance of type %s found for feign client %s","messagePattern":"No (.+?) instance of type (.+?) found for feign client (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java","lineNumber":152,"sourceCode":"\t\t\t\t\t\t\t\tbeanName, \"fallbackFactory\", fallbackFactory,\n\t\t\t\t\t\t\t\tFallbackFactory.class);\n\t\t\t\t\t\treturn new SentinelInvocationHandler(target, dispatch,\n\t\t\t\t\t\t\t\tfallbackFactoryInstance);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn new SentinelInvocationHandler(target, dispatch);\n\t\t\t\t}\n\n\t\t\t\tprivate Object getFromContext(String name, String type,\n\t\t\t\t\t\tClass fallbackType, Class targetType) {\n\t\t\t\t\tFeignClientFactory factory = Builder.this.feignClientFactory;\n\t\t\t\t\tif (factory == null) {\n\t\t\t\t\t\tthrow new IllegalStateException(\"FeignClientFactory not initialized\");\n\t\t\t\t\t}\n\t\t\t\t\tObject fallbackInstance = factory.getInstance(name,\n\t\t\t\t\t\t\tfallbackType);\n\t\t\t\t\tif (fallbackInstance == null) {\n\t\t\t\t\t\tthrow new IllegalStateException(String.format(\n\t\t\t\t\t\t\t\t\"No %s instance of type %s found for feign client %s\",\n\t\t\t\t\t\t\t\ttype, fallbackType, name));\n\t\t\t\t\t}\n\t\t\t\t\t// when fallback is a FactoryBean, should determine the type of instance\n\t\t\t\t\tif (fallbackInstance instanceof FactoryBean<?> factoryBean) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tfallbackInstance = factoryBean.getObject();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\t\tthrow new IllegalStateException(type + \" create fail\", e);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fallbackInstance == null) {\n\t\t\t\t\t\t\tthrow new IllegalStateException(type + \" FactoryBean returned null\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfallbackType = fallbackInstance.getClass();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!targetType.isAssignableFrom(fallbackType)) {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java#L134-L170","documentation":"When resolving a fallback or fallbackFactory, SentinelFeign asks the FeignClientFactory for an instance of the declared type. If the factory returns null (no bean of that type in the child context), this formatted IllegalStateException is thrown, naming the role (fallback/fallbackFactory), the expected type, and the feign client name.","triggerScenarios":"Declaring @FeignClient(fallback = MissingFallback.class) where MissingFallback is not a Spring bean (no @Component) or not registered in the feign child context. Same for fallbackFactory.","commonSituations":"Forgetting to annotate the fallback class as a Spring component. Putting the fallback in a package not component-scanned. Declaring fallback on an interface whose fallback bean is lazy and not yet created.","solutions":["Annotate the fallback/fallbackFactory class with @Component (or register it as a bean).","Ensure the class is within the component-scan packages of the application.","Confirm the fallback type matches the feign client interface exactly.","If the bean must be lazy, ensure the feign child context can still resolve it on demand."],"exampleFix":"// before\npublic class MyApiFallback implements MyApi { ... }\n// after\n@Component\npublic class MyApiFallback implements MyApi { ... }","handlingStrategy":"validation","validationCode":"<T> T resolveOrThrow(FeignClientFactory f, String name, Class<T> type) {\n  T inst = f.getInstance(name, type);\n  if (inst == null) throw new IllegalStateException(\"No \" + type.getSimpleName() + \" bean found in context \" + name);\n  return inst;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Annotate fallback/fallbackFactory classes with @Component.","Keep fallback classes within component-scan packages.","Ensure the fallback type implements the feign interface."],"tags":["sentinel","feign","fallback","bean-resolution"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}