resilience4j-spring-boot-2批注@Retry,@CircuitBreaker ...被完全忽略

问题描述

我花了整整一天的时间来找出为什么这行不通,所以我认为如果我分享问题和答案可能会有用。

Resilience4j library从Spring Boot 2提供了一个优雅的基于注释的解决方案。您所要做的只是用一个提供的注释(例如retrofitService注释一个方法(或一个类)。 ,@CircuitBreaker@Retry@RateLimiter@Bulkhead,并自动添加适当的弹性模式。

我向Maven pom.xml添加了预期的依赖项:

@Thread

现在编译器很高兴,因此我可以添加注释:

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

程序可以编译,运行,但是注释将被完全忽略

解决方法

根据resilience4j-spring-boot2 documentation

该模块希望在运行时已提供spring-boot-starter-actuatorspring-boot-starter-aop

因此,整个技巧是向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>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...