1.pom
代码语言:javascript
复制<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.yml
代码语言:javascript
复制feign:
sentinel:
enabled: true
3.业务类
代码语言:javascript
复制@Component
@FeignClient(name = "nacos-payment-provider",fallback = PaymentServiceFallback.class)
public interface PaymentService {
@GetMapping(value = "/payment/nacos/{id}")
public String getPayment(@PathVariable("id") Long id);
}
代码语言:javascript
复制@Component
public class PaymentServiceFallback implements PaymentService {
@Override
public String getPayment(Long id) {
return "服务降级";
}
}