Spring Cloud 微服务开发:入门、进阶与源码剖析 —— 12.3 Sentinel 进阶实战

12.3 Sentinel 进阶实战

12.3.1 Sentinel 整合 Feign 和 RestTemplate

Sentinel目前已经同时支持Feign和RestTemplate,需要我们引入对应的依赖,在使用Feign的时候需要在配置文件中打开Sentinel对Feign的支持:feign.sentinel.enabled=true,同时需要加入openfeign starter依赖使sentinel starter中的自动化配置类生效。在使用RestTemplate的时候需要在构造RestTemplate的Bean的时候加上@SentinelRestTemplate注解,开启Sentinel对RestTemplate的支持。

  1. 创建父工程ch12_2:

父工程pom.xml如下:

代码清单:


<dependency>
    <groupId>org.springframework.boot

猜你喜欢

转载自blog.csdn.net/meteor_93/article/details/105238438