Resilence4j 1.7.1 未执行 - jdk 17

问题描述 投票:0回答:2

我不确定这是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 boot 依赖项,错误消失了,但它没有执行任何操作,因为调用像正常异常一样失败。我有一个 APi 调用另一个 api。甚至执行器的健康状况也没有显示出任何 resilence4j 属性。不知道我在这里缺少什么。如果有帮助,我们将不胜感激。这是我所做的:

构建.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()
}

实现@Circutebreaker的服务类;

...
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;
    }
}

应用程序.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
spring-boot circuit-breaker resilience4j spring-cloud-circuitbreaker
2个回答
2
投票

事实证明问题出在 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'

0
投票

将resilience4j降级到1.7.0,你的问题将得到解决

© www.soinside.com 2019 - 2024. All rights reserved.