pom文件
<!-- 熔断依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- 引入openfeign依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
yaml文件
# Feign熔断配置
feign:
hystrix:
enabled: true //一级目录
使用误区
1、PathVariable传参方式
controller层
@GetMapping("/listAll/{id}")
public List<Map> listById(
@PathVariable(name = "id") Integer id
)
feignClient层( @PathVariable(name = "id")路径传参一定要加这个 否则报错)
@FeignClient("ruoyi-cms")
public interface CmsClient {
@GetMapping("/goods/listAll/{id}")
List<Map> list(
@PathVariable(name = "id") Integer id
) ;
}
2、RequestParam传参
controller层(当controller层没有指定传参方式时默认是RequestParam)
@PostMapping("/listAll")
public List<Map> listById(
Integer id
)
feignClient层 (当feignClient 层没有 @ 指定传参方式时 默认为 @RequestBody 所以要手动添加@RequestParam("id")
@FeignClient("ruoyi-cms")
public interface CmsClient {
@GetMapping("/goods/listAll")
List<Map> list(
Integer id
) ;
}
标签:传参,PathVariable,openfeign,public,熔断,Integer,id,cloud
From: https://blog.csdn.net/ZX115675/article/details/140680497