当前位置:网站首页>【微服务|Sentinel】sentinel整合openfeign
【微服务|Sentinel】sentinel整合openfeign
2022-07-01 22:29:00 【步尔斯特】
步骤
上文我们谈到sentinel的注解@SentinelResource以及其对异常兜底方案的处理。
如果对每一个接口都做各自的处理,会有诸多不便,所以我们可以整合openfeign对限流降级策略统一处理。
第一步:打开feign对sentinel的支持
feign:
sentinel:
enabled: true
第二步:编写兜底方案
import com.ossa.feign.api.producer.ProducerFeign;
import org.springframework.stereotype.Service;
/** * @author issavior */
@Service
public class ProducerFeignFallback implements ProducerFeign {
@Override
public String producerById(String id) {
String msg = "fallback限流方法";
return id + msg;
}
}
第三步:修改@FeignClient注解
import com.ossa.feign.config.FeignClientConfig;
import com.ossa.feign.fallback.ProducerFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** * @author issavior */
@FeignClient(value = "ossa-service-producer", configuration = FeignClientConfig.class,fallback = ProducerFeignFallback.class)
public interface ProducerFeign {
/** * 根据ID查询商品 * * @param id 商品的主键ID * @return 相关商品的信息 */
@GetMapping(value = "/producer/{id}")
String producerById(@PathVariable("id") String id);
}
问题
问题描述:
Caused by: java.lang.IllegalStateException: Ambiguous mapping
分析:
在feign的接口上使用@RequestMapping注解,就会导致这个问题。
Controller这一个控制层请求映射了两个方法,且在Controller中重复了,所以报错。 或者说,如果一个项目中有两个@RequestMapping(“/xxx”)完全相同就会报 java.lang.IllegalStateException,controller所在的模块依赖了client所在的模块才导致冲突的。
解决方案:
去掉@RequestMapping

边栏推荐
- Convergence and disposal suggestions of some Internet exposure surfaces
- MySQL -- index of MyISAM storage engine
- “35岁,公司老总,月薪2万送外卖“:时代抛弃你,连声再见都没有
- 【Kotlin 第三方 】coil koltin协程图片加载库Coil类似Glide的图片加载第三方
- tcpdump命令使用详解
- Summary of "performance testing" of software testing, novice will know the knowledge points on the road
- Programming English vocabulary notebook
- 下班前几分钟,我弄清了v-model与.sync的区别
- A few minutes before work, I found out V-model and The difference between sync
- Cisco exam -- redundant network
猜你喜欢

Introduction and use of plantuml

Digital currency: far-reaching innovation

Cisco -- highly available and reliable network examination

微信个人小商店一键开通助手小程序开发
![Jerry's burning of upper version materials requires [chapter]](/img/65/fcd804e00dc08a2bd056e8e6493829.png)
Jerry's burning of upper version materials requires [chapter]

Congratulations on the release of friends' new book (send welfare)

tcpdump命令使用详解

Unable to climb hill sort, directly insert sort

14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向

常见的二十种软件测试方法详解(史上最全)
随机推荐
Jielizhi Bluetooth headset quality control and production skills [chapter]
“信任机器”为发展赋能
软件测试之「 性能测试」总结,新手上路必会知识点
【微服务|Sentinel】SentinelResourceAspect详解
【Kotlin 第三方 】coil koltin协程图片加载库Coil类似Glide的图片加载第三方
Force buckle 710 Random numbers in the blacklist
openresty 负载均衡
思科考试--路由的概念和配置考试
Jerry's records are powered by Vbat with a power supply voltage of 4.2V [chapter]
locust的使用
Happy number [fast and slow pointer of ring PROBLEMS]
shell 自定义函数
El input text field word limit, beyond which the display turns red and input is prohibited
[MySQL] index classification
Electron学习(三)之简单交互操作
轉載csdn文章操作
Map container
关于游戏性能优化的一些感想
转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
Redis~02 缓存:更新数据时如何保证MySQL和Redis中的数据一致性?