我花了一整天的时间试图找出为什么这个方法不起作用,所以我认为如果我能分享这个问题和答案,可能会很有用。
Resilience4j库从Spring 2中提供了一个优雅的基于注释的解决方案,您所需要做的就是用所提供的注释之一注释一个方法(或一个类),例如@CircuitBreaker、@Retry、@RateLimiter、@Bulkhead、@Thread,并自动添加适当的恢复模式。
我将预期的依赖项添加到Maven pom.xml中:
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>${resilience4j.version}</version>
</dependency>现在编译器很高兴,所以我可以添加注释:
...
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) {
...
}
}程序编译、运行,但是注释被完全忽略了,。
发布于 2020-10-08 19:23:21
该模块期望在运行时已经提供了
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>https://stackoverflow.com/questions/64269326
复制相似问题