alibaba/spring-cloud-alibaba · error · IllegalStateException

No %s instance of type %s found for feign client %s

Error message

No %s instance of type %s found for feign client %s

What it means

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.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java:152

								beanName, "fallbackFactory", fallbackFactory,
								FallbackFactory.class);
						return new SentinelInvocationHandler(target, dispatch,
								fallbackFactoryInstance);
					}

					return new SentinelInvocationHandler(target, dispatch);
				}

				private Object getFromContext(String name, String type,
						Class fallbackType, Class targetType) {
					FeignClientFactory factory = Builder.this.feignClientFactory;
					if (factory == null) {
						throw new IllegalStateException("FeignClientFactory not initialized");
					}
					Object fallbackInstance = factory.getInstance(name,
							fallbackType);
					if (fallbackInstance == null) {
						throw new IllegalStateException(String.format(
								"No %s instance of type %s found for feign client %s",
								type, fallbackType, name));
					}
					// when fallback is a FactoryBean, should determine the type of instance
					if (fallbackInstance instanceof FactoryBean<?> factoryBean) {
						try {
							fallbackInstance = factoryBean.getObject();
						}
						catch (Exception e) {
							throw new IllegalStateException(type + " create fail", e);
						}
						if (fallbackInstance == null) {
							throw new IllegalStateException(type + " FactoryBean returned null");
						}
						fallbackType = fallbackInstance.getClass();
					}

					if (!targetType.isAssignableFrom(fallbackType)) {

View on GitHub (pinned to 115d590110)

Solutions

  1. Annotate the fallback/fallbackFactory class with @Component (or register it as a bean).
  2. Ensure the class is within the component-scan packages of the application.
  3. Confirm the fallback type matches the feign client interface exactly.
  4. If the bean must be lazy, ensure the feign child context can still resolve it on demand.

Example fix

// before
public class MyApiFallback implements MyApi { ... }
// after
@Component
public class MyApiFallback implements MyApi { ... }
Defensive patterns

Strategy: validation

Validate before calling

<T> T resolveOrThrow(FeignClientFactory f, String name, Class<T> type) {
  T inst = f.getInstance(name, type);
  if (inst == null) throw new IllegalStateException("No " + type.getSimpleName() + " bean found in context " + name);
  return inst;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/7b693852786c02a7. Report an issue: GitHub.