I am trying to build a simple CircuitBreaker in my Spring Boot (which uses Swagger).
The idea is that the first app, calls another which can be Up or Down, I want to implement a CircuitBreaker which gives an error message if the second app is down.
The main problem is that with I try to use the @CircuitBreaker annotation, says that it cannot be resolved to a type.
import...
import io.github.resilience4j.*;
public class AccountServiceImpl implements AccountService {
Autowired private RestTemplate restTemplate;
@CircuitBreaker( name = "test", fallbackMethod = "fallback")
public void createAccount(ConsentRequestDTO consent) {
//code which makes the post
//
}
public String fallback() {
return "fallback-exceptiont";
}
}
My pom.xml is
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.resilience4j/resilience4j-retry -->
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-circuitbreaker</artifactId>
<version>1.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.resilience4j/resilience4j-core -->
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-core</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-all</artifactId>
<version>1.7.0</version>
</dependency>
I dont know how to solve the error. Maybe its the dependencies? I tried withouth the annotation, using
CircuitBreakerConfig config = CircuitBreakerConfig.ofDefaults()
But it gives the same error, "cannot be resolved".
Based on the demo circuit breaker you dont need
Because you already have
spring-cloud-starter-circuitbreaker-reactor-resilience4j
. Use these imports may solve your issue