问题描述
我花了整整一天的时间来找出为什么这行不通,所以我认为如果我分享问题和答案可能会有用。
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-actuator
和spring-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>