Reputation: 1594
I am using resilience4j with SpringBoot. I see that the resilience4j annotations work only if they are placed in the class which throws the exception. If the class is extended by another class & the parent class has the annotation then the retries do not work.
Resilience4j Config
resilience4j.retry:
instances:
service:
maxRetryAttempts: 5
waitDuration: 1000
retryException:
- com.common.exception.RetriableException
Parent Class
@Retry(name = "service")
@Component
public class httpClient extends client{
// This method is invoked from outside
public HttpResponse<T> getResponse(
String url, Class<T> responseType) {
return super.getResponse(url, requestEntity, responseType);
}
}
Child Class
@Retry(name = "service") // Without this line, the retries don't work, even though it is present in the parent class
@Component
public class client{
public HttpResponse<T> getResponse(
String url, Class<T> responseType) {
//Impl which throws RetriableException
}
}
Is this the expected behaviour ? Can you let me know if I am missing something
Upvotes: 0
Views: 1661
Reputation: 67317
I never used Resilience4j before, but what I can tell you about Java annotations in general is:
@Foo class Base
, can also be abstract) can be inherited by a subclass (something like class Sub extends Base
) if and only if the annotation class itself carries the meta annotation @Inherited
.Having said that and looking at the @Retry
annotation, you will notice that there is no @Inherited
annotation there, so it also cannot work in your case.
If there is another way (e.g. via reflection) to get this done in Resilience4j, I do not know because, as I said, I never used it before.
Upvotes: 2