【问题标题】:Spring cloud Netflix-Hystrix gradle dependency not allowing spring boot application to startSpring cloud Netflix-Hystrix gradle 依赖项不允许 Spring Boot 应用程序启动
【发布时间】:2021-06-21 01:15:54
【问题描述】:

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

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

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 文件的 sn-p。

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}"
    }
}

【问题讨论】:

    标签: java spring-boot microservices hystrix hystrix-dashboard


    【解决方案1】:

    相信你也应该指定依赖的version

    implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.2.7.RELEASE'
    

    【讨论】:

    • 这行得通,但我已经在上面提到的 sn-p 部分指定了版本。与版本兼容性有关吗?由于我为 eureka 服务器指定了上面提到的版本,因此它可以工作,但在 hystrix 依赖的情况下不起作用。有什么原因吗?
    • 您可以将该变量用于版本,例如:implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix:${springCloudVersion}'
    • 您确定版本设置正确吗?它应该是该软件包的 mavenCentral 上的版本之一,与您当前使用的版本不同 (2020.0.2)
    • spring-cloud-starter-netflix-hystrix 的可用版本可以查看herespring-cloud-dependencies 的可用版本可以查看here。所以你应该简单地添加一个新变量,比如set('springHystrixVersion', "2.2.7.RELEASE"),并在你获取包时使用它:implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix:${springHystrixVersion}'
    • 请参考下面的链接,它是关于Spring Cloud Netflix Projects Entering Maintenance Mode的,如果我们使用最新的spring-cloud-dependencies,似乎我们应该手动指定spring-cloud-starter-netflix-hystrix的版本:github.com/spring-cloud/spring-cloud-release/wiki/…spring.io/blog/2018/12/12/…
    【解决方案2】:

    我遇到了同样的问题,并在他们说的地方找到了这个官方 link

    正如宣布的那样,以下模块已从 spring-cloud-netflix 中删除:

    • ...
    • spring-cloud-netflix-hystrix
    • spring-cloud-starter-netflix-hystrix
    • ...(其他一些 spring-cloud-netflix-* 子项目)

    所以看起来 Hystrix 依赖将不再由 spring-cloud-release 管理。这就是您必须手动指定版本的原因。 无论如何,这并不意味着 Spring Hystrix 已经/将被弃用,但我还不知道那部分......

    我现在正在回答这个问题,因为我在挖掘了很多之后才发现它并且不希望任何人再次这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-04
      • 2016-03-31
      • 1970-01-01
      • 2015-06-28
      • 2023-03-10
      • 2021-06-25
      • 2016-09-17
      • 2018-08-29
      相关资源
      最近更新 更多