Spring Cloud Netflix-Hystrix gradle 依赖项不允许 Spring Boot 应用程序启动

Aja*_*jay 4 java spring-boot hystrix microservices hystrix-dashboard

我使用Spring-BootEureka server构建了简单的微服务应用程序。现在,我想添加容错功能,以防 Eureka 服务器中注册的任何服务出现故障。所以,我使用了netflix-hystrix gradle dependency。但这种依赖性导致我的应用程序崩溃。

运行应用程序时,我收到以下错误消息:

Execution failed for task ':compileJava'. Could not resolve all files for configuration ':compileClasspath'. Could not find org.springframework.cloud:spring-cloud-starter-netflix-hystrix:.

作为参考,我添加了build.gradle文件的片段。

plugins {
    id 'org.springframework.boot' version '2.4.4'
}

ext {
    set('springCloudVersion', "2020.0.2")
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}
Run Code Online (Sandbox Code Playgroud)

Cos*_*iță 6

我相信您还应该指定依赖项的版本:

implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.2.7.RELEASE'
Run Code Online (Sandbox Code Playgroud)

  • 可以在[此处](https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix)检查“spring-cloud-starter-netflix-hystrix”的可用版本,以及可以在[此处](https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependency)检查“spring-cloud-dependency”的内容。因此,您应该简单地添加一个新变量,例如 `set('springHystrixVersion', "2.2.7.RELEASE")`,并在获取包时使用它: `implementation 'org.springframework.cloud:spring-cloud-starter -netflix-hystrix:${springHystrixVersion}'` (3认同)