首页 > 解决方案 > 带有 Hystrix 的 Spring Boot

问题描述

我正在为我的大学项目使用带有 Hystrix 的 Spring Boot。我遇到的问题是,当我将 Netflix Hystrix 依赖项添加到 pom.xml 文件并运行程序时,它会抛出一个名为 AbstractMethodError 的错误:null,但如果没有 Netflix Hystrix 依赖项,程序运行时不会出现任何错误。我该如何解决这个问题?

这些是我的依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

标签: spring-bootspring-cloudspring-cloud-netflixhystrix

解决方案


这是由于依赖项不匹配造成的。应用程序正在尝试调用一个抽象方法,但它没有找到该方法。所以,它抛出了空异常。

使用两个依赖 netflix-hystrix-dashboard 和 hystrix,如下所示。

 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>

推荐阅读