Quick revision
The short answer
Resilience4j finds the fallback by name and signature: it must be in the same class, have the same return type, and take the same parameters as the protected method plus one exception parameter as the last argument. The type of that exception parameter decides which failures it handles, and when several fallbacks share the name, the most specific match is chosen. If no method matches, Resilience4j fails with a NoSuchMethodException-style error at runtime. The annotations also need the Spring AOP starter and work only on calls through the proxy, so private methods and self-invocation are not intercepted, and we test fallbacks by forcing the dependency to fail.
What to remember
In this answer, we saw that Resilience4j links a fallback by name, so its signature must match exactly: same class, same return type, same parameters, plus one exception parameter last whose type selects which failures it handles, with the most specific match chosen. The annotations need the AOP starter and only intercept calls through the proxy, so private methods and self-invocation are unprotected, and a test that forces the dependency to fail catches mistakes early.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Resilience4j finds the fallback by name and signature: it must be in the same class, have the same return type, and take the same parameters as the protected method plus one exception parameter as the last argument. The type of that exception parameter decides which failures it handles, and when several fallbacks share the name, the most specific match is chosen. If no method matches, Resilience4j fails with a NoSuchMethodException-style error at runtime. The annotations also need the Spring AOP starter and work only on calls through the proxy, so private methods and self-invocation are not intercepted, and we test fallbacks by forcing the dependency to fail.
Why this question is asked
Fallbacks are where a circuit breaker pays off for users: instead of an error, they get cached data or a sensible default. But a fallback that is never called, or that crashes the call with a reflection error, is worse than none, because the team believes they are protected. Interviewers ask about the rules because the mistakes are small and easy to make. In this answer, we will recap how Resilience4j looks up a fallback, reproduce the error, fix the signature, see how exception types select a fallback, look at the proxy rules that silently disable everything, and finish with how to test it.
1A Quick Recap: How Resilience4j Finds a Fallback
When we write @CircuitBreaker(name = "inventory", fallbackMethod = "fallback"), we give Resilience4j only a name, a string. At runtime, when the protected call fails, the aspect looks for a method called fallback in the same class whose signature fits: the same return type as the protected method, the same parameter types in the same order, and one extra parameter at the end whose type is Throwable or a subclass of it. It finds that method by reflection and calls it with the original arguments plus the exception.
Because the link is only a name, the compiler cannot check it. A typo or a mismatched type shows up only when the protected call actually fails, often for the first time in production.
2Reproducing the Error
Here is a fallback that looks reasonable but does not match.
The protected method takes (String, int), so Resilience4j looks for fallback(String, int, SomeThrowable). Our method takes only (String), so there is no match and the call fails with a lookup error instead of our default. The exact exception class and message depend on the Resilience4j version, but it always names a fallback signature it could not find. Other common mismatches are a different return type, such as Optional<Stock> instead of Stock, a wrapper type instead of a primitive (Integer for int), or the exception parameter placed first instead of last.
3Fixing the Signature
The fix is to copy the protected method's signature exactly and add the exception parameter at the end.
- Protected call throwsfor example
CallNotPermittedException - Find methods named fallbackin the same class
- Same return type and parameters + one Throwable last?YesCandidateNoIgnored
- Any candidate's exception type matches?YesCall the most specific oneNoRethrow the original exception
- No candidate at alllookup error at runtime
5 steps in order. Play them, or step through them one at a time.
Notice that the fallback itself can be private in current Resilience4j versions, because it is invoked by reflection, not through the proxy. The protected method is the one that must be reachable through the proxy. For asynchronous or reactive methods the same rule holds: if stock returns CompletableFuture<Stock> or Mono<Stock>, the fallback must return the same type.
4Choosing a Fallback by Exception Type
The exception parameter is not just decoration; it selects which failures a fallback handles. We can declare several fallbacks with the same name and different exception types, and Resilience4j calls the one whose exception type is the closest match.
So if the only fallback declares IOException, a CallNotPermittedException from an open breaker is not handled by it and reaches the caller. Declaring Exception or Throwable catches everything, which is convenient but can hide bugs, so many teams declare specific types on purpose.
5The Proxy Rules That Disable Fallbacks Silently
Even a perfect signature does nothing if the aspect never runs. Resilience4j's annotations are applied by Spring AOP, so the application needs the AOP starter, spring-boot-starter-aop in Boot 3 (renamed spring-boot-starter-aspectj in Boot 4; check your version). Without it, the annotations are ignored: no breaker, no fallback, no error.
Spring AOP works through a proxy, a wrapper object around the bean, and only calls that enter through the proxy are intercepted. If another method in StockService calls this.stock(...), it calls the real object and skips the aspect. A private or final protected method cannot be intercepted by the class-based proxy either. In all these cases the call simply runs unprotected, and a failure propagates as if no annotation existed. The fix is to call the method from another bean, or to use the CircuitBreaker programmatically with Decorators.
6Testing the Fallback
Fallbacks run rarely, so we test them on purpose. In a Spring Boot test, we start the context so the proxy is real, make the dependency fail with a mock or WireMock, and assert that the fallback's result came back. We also force the breaker open with CircuitBreakerRegistry and check the CallNotPermittedException path.
The first test would have caught our original bug immediately, because the lookup error would have failed it.
7Follow-up questions
Can the fallback be in a different class?
Not with the annotation's fallbackMethod; it must be in the same class as the protected method. If we want shared fallback logic, the fallback method in our class can delegate to another bean, or we use the programmatic Decorators API with withFallback.
Should the fallback call another remote service?
Usually not. A fallback should be fast and local, such as a cache or a default, because a remote fallback can fail for the same reason and adds load during an incident.
Why did nothing happen at all, not even an error?
That points to the aspect not running: the AOP starter is missing, the method is private, or it was called from inside the same class. Logging the class of the injected bean (it should be a CGLIB proxy) or checking the breaker's metrics quickly shows whether calls pass through Resilience4j.
8Conclusion
In this answer, we saw that Resilience4j links a fallback by name, so its signature must match exactly: same class, same return type, same parameters, plus one exception parameter last whose type selects which failures it handles, with the most specific match chosen. The annotations need the AOP starter and only intercept calls through the proxy, so private methods and self-invocation are unprotected, and a test that forces the dependency to fail catches mistakes early.
Open with
The fallback is found by name at runtime, so the signature has to match exactly. It must be in the same class as the annotated method, return the same type, take the same parameters in the same order, and add one exception parameter as the last argument.
Then, if they want more
In the failing case the fallback was probably missing a parameter, had the exception first, or returned a different type, so Resilience4j could not find a matching method and threw a lookup error instead of calling it. The exception parameter also selects what the fallback handles.
I can declare several fallbacks with the same name, for example one taking CallNotPermittedException to serve cached data when the breaker is open and one taking Exception for everything else, and Resilience4j calls the most specific match. If none matches the thrown type, the original exception propagates.
The fallback itself can be private, because it is called by reflection, but the protected method must go through the Spring proxy. That means the AOP starter must be on the classpath, the method must not be private, and it must be called from another bean, not from this inside the same class, otherwise nothing is intercepted at all.
Finally, I would test it: a Spring Boot test where the client mock throws, asserting that the fallback result comes back, and another that forces the breaker open through the registry. That test would have caught this bug before production.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A method has @CircuitBreaker(name = "inventory", fallbackMethod = "fallback") and the...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/023dfb4fbf/