前景
本人机器全部依赖如下
springboot 2.5.5
springcloud 2020.0.4
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.springcloud</groupId>
<artifactId>book</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>book</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
</dependencies>
</project>
遇到的问题
使用openfeign的Hytrix断路器配置无效,无法降级。
问题初步排查
# 启动feign中的hystrix组件
feign:
circuitbreaker: //springcloud 2020版本应将Hytrix修改为circuitbreaker
#开启feign的hystrix支持,默认是false
enabled: true
springcloud 2020版本应将Hytrix修改为circuitbreaker,我修改后yml文件内报错消失,但是Hytrix功能仍不可用。
后根据网络上添加了netflix-hystrix新依赖,并在主类开启@EnableHystrix
仍不可用。
附上我的业务实现代码
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "member",fallback = MemberClient.MemberClientFallBack.class)
public interface MemberClient {
@GetMapping("/check")
public MemberResult checkMobile(@RequestParam("mobile") String mobile);
@Component
static class MemberClientFallBack implements MemberClient{
@Override
public MemberResult checkMobile(String mobile) {
MemberResult mr = new MemberResult();
mr.setCode("0");
mr.setMessage("success");
return mr;
}
}
}
目前状况就是无法进入MemberClientFallBack 实现类,实现断路降级功能。
还有一张图附一下,不知道有没有关系,关于Enablecircuitbreker弃用的问题
求教
求路过的各位大佬,不吝赐教!!!不胜感激,我会积极回复消息,并提供补充。