OpenFeign的使用
1.在主启动类上添加@EnableFeignClients注解

2.配置服务层接口,在接口上添加@FeignClient(value = "服务注册中心的名字")
在这里名添加的接口需要和提供者的接口路径保持一致
@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface PaymentFeignService {
    @GetMapping(value = "/payment/get/{id}")
     CommonResult<Payment> getPaymentById(@PathVariable("id") Long id);
}
提供者的controller

3.创建消费者controller进行服务层调用
@RestController
@Slf4j
public class OrderFeignController {
    @Resource
    private PaymentFeignService paymentFeignService;
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        return paymentFeignService.getPaymentById(id);
    }

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号