我不确定这是jdk兼容性问题,还是遗漏了什么。我尝试了resilence4j git依赖,如下所示:
implementation group: 'io.github.resilience4j', name: 'resilience4j-spring-boot2', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-retry', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-bulkhead', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-ratelimiter', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-circuitbreaker', version: '1.7.1'
但我犯了错误;
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfiguration.createCircuitBreakerRegistry(CircuitBreakerConfiguration.java:141)
The following method did not exist:
io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry.of(Ljava/util/Map;Lio/github/resilience4j/core/registry/RegistryEventConsumer;Lio/vavr/collection/Map;)Lio/github/resilience4j/circuitbreaker/CircuitBreakerRegistry;
最后,我创建了spring引导依赖项,错误消失了,但是它什么也不做,因为调用会像正常的异常一样失败。我有一个api,它调用另一个APi。甚至执行器的健康状况也没有显示任何resilence4j属性。不知道我在这里错过了什么。帮个忙会很感激的。以下是我所做的:
build.gradle
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.0")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '2.6.1'
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.10'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
服务类,其中@断路器是实现;
...
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
@Service
public class UserInfoService {
public static final Logger LOG = LogManager.getLogger(UserInfoService.class);
@Autowired
private AppConfiguration appConfig;
@CircuitBreaker(name = "userInfoService",
fallbackMethod = "testMethod")
public GetUserOutputVO getUserInfoById(String id) {
LOG.info("--- Beginning of method UserInfoService.getUserInfoById()---");
return appConfig.getUserInfoWebclient().get()
.uri("/users/id/" + id)
.retrieve()
/*.onStatus(httpStatus -> HttpStatus.NOT_FOUND.equals(httpStatus),
clientResponse -> Mono.empty())*/
.bodyToMono(GetUserOutputVO.class)
.block();
}
public GetUserOutputVO testMethod(String id) {
GetUserOutputVO resp = new GetUserOutputVO();
UserInfo userInfo = new UserInfo();
userInfo.setFirstName("Its a test for fallback");
resp.setUserInfo(userInfo);
return resp;
}
}
application.yml
server:
port: 8097
spring:
application:
name: profile-mgmt-api
jpa:
# hibernate:
# ddl-auto: create
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: true
datasource:
url: "<url>"
username: username
password: password
resilience4j.circuitbreaker:
instances:
userInfoService:
registerHealthIndicator: true
ringBufferSizeInClosedState: 5
ringBufferSizeInHalfOpenState: 3
waitDurationInOpenState: 10s
failureRateThreshold: 50
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
- java.util.concurrent.TimeoutException
- org.springframework.web.client.ResourceAccessException
- java.net.ConnectException
management:
endpoints:
enabled-by-default: false
endpoint.health:
enabled: true
show-details: always
发布于 2022-01-19 16:41:03
事实证明,问题是1.7.1,当我按照评论中的建议将评级降至1.7.0时,它起了作用。这里是我的依赖关系。
implementation group: 'io.github.resilience4j', name: 'resilience4j-spring-boot2', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-retry', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-bulkhead', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-ratelimiter', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-circuitbreaker', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-timelimiter', version: '1.7.0'
https://stackoverflow.com/questions/70771718
复制相似问题