resilience4j-spring-boot-2 annotations (@Retry, @CircuitBreaker...) are completely ignored

4.4k views Asked by At

I spent a whole day trying to find why this does not work so I think it might be useful if I share the question and the answer.

The Resilience4j library provides an elegant annotation-based solution from Spring Boot 2. All you need to do is just annotate a method (or a class) with one of the provided annotations, such as @CircuitBreaker, @Retry, @RateLimiter, @Bulkhead, @Thread and the appropriate resilience pattern is automagically added.

I added the expected dependency to the Maven pom.xml:

<dependency>
    <groupId>io.github.resilience4j</groupId>
    <artifactId>resilience4j-spring-boot2</artifactId>
    <version>${resilience4j.version}</version>
</dependency>

Now the compiler is happy, so I can add the annotations:

...
import org.springframework.stereotype.Service;
import io.github.resilience4j.retry.annotation.Retry;
...

@Service
public class MyService {
    ...
    @Retry(name = "get-response")
    public MyResponse getResponse(MyRequest request) {
        ...
    }
}

The program compiles, runs, however the annotations are completely ignored.

1

There are 1 answers

0
Honza Zidek On BEST ANSWER

According to the resilience4j-spring-boot2 documentation:

The module expects that spring-boot-starter-actuator and spring-boot-starter-aop are already provided at runtime.

So the whole trick is to add also the missing dependencies to the Maven pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>