Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 816
Honza Zidek Avatar asked Oct 27 '25 14:10

Honza Zidek


1 Answers

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>
like image 157
Honza Zidek Avatar answered Oct 30 '25 05:10

Honza Zidek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!