本文基于springboot-2.0.6RELEASE+cloud-F.SR2
Feign环境下:只需两步
1.在原使用hystrix的模块中添加如下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>
2.在application.yml 中添加feign.sentinel.enabled=true 即可为Feign启用Sentinel支持:
# 去掉
# feign.hystrix.enabled: true
# 改为如下即可
feign.sentinel.enabled: true
Ribbon环境下:
1.先去除Spring Cloud Netflix Hystrix( spring-cloud-starter-netflix-hystrix )的依赖,再添加sentinel依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>
2.再在构造RestTemplate的时候加上@SentinelRestTemplate注解即可
@Bean
@SentinelRestTemplate
public RestTemplate restTemplate() {
return new RestTemplate();
}
---------------------
作者:Mr_lyh
来源:CSDN
原文:https://blog.csdn.net/Mr_lyh/article/details/86700810
版权声明:本文为博主原创文章,转载请附上博文链接!