Netflix / Hystrix

Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.
24.12k stars 4.7k forks source link

FallbackDefinitionException: fallback method wasn't found #1782

Open ghost opened 6 years ago

ghost commented 6 years ago

Hello, I am getting this exception even though the fallback method signature is same as actual method. The version of lib is hystrix-javanica-1.5.12 My code snippet:

@HystrixCommand(defaultFallback="getDefaultProductInventory")
@GetMapping("/{productCode}")
public ResponseEntity<ProductInventoryResponse> getProductInventory(@PathVariable String productCode) 
{
    // business logic
}
public ResponseEntity<ProductInventoryResponse> getDefaultProductInventory(String productCode) 
{
    //default response entity object creation logic
}

When debugged, it looks like inside method

com.netflix.hystrix.contrib.javanica.utils.MethodProvider.FallbackMethodFinder.doFind(Class<?>, Method, boolean) 

the condition

if (isDefault()) 
{
    fallbackParameterTypes = new Class[0];
} 
else 
{
    fallbackParameterTypes = commandMethod.getParameterTypes();
}

is always evaluated to true in my case and because of this fallbackParameterTypes array is empty and the method

com.netflix.hystrix.contrib.javanica.utils.MethodProvider.getMethod(Class<?>, String, Class<?>...) 

which is called later is trying to find fallback method signature with no parameters. But when I change my fallback method signature to

public ResponseEntity<ProductInventoryResponse> getDefaultProductInventory() {
    //default response entity object creation logic
}

all works fine as method signature matches. I am not able to understand why this is happening. I think as per reference documents, the fallback method signature should match with the actual method. But it seems this is not happening here. I want the productCode to be part of fallback method signature.

Can somebody tell me where is the issue in this case?

Thanks.

farambarri commented 5 years ago

I am facing exactly the same issue.

farambarri commented 5 years ago

I detected what is wrong.

please, try changing this

@HystrixCommand(defaultFallback="getDefaultProductInventory")

to

@HystrixCommand(fallbackMethod="getDefaultProductInventory")

ChengxiangA commented 2 years ago

@farambarri Thanks very much!!!