5、OpenFeign注意点

服务提供者8001,PaymentController

@GetMapping(value = "/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("*****查询结果:"+payment);
        if (payment!=null){  //说明有数据,能查询成功
            return new CommonResult(200,"查询成功,serverPort: "+serverPort,payment);
        }else {
            return new CommonResult(444,"没有对应记录,查询ID:"+id,null);
        }
    }

 

消费者80,PaymentFeignService

@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface PaymentFeignService {
​
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult getPaymentById3(@PathVariable("id") Long id);
}

 

 

消费者80,OrderFeignController


@RestController
public class OrderFeignController {
​
    @Resource
    private PaymentFeignService paymentFeignService;
​
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult getPaymentById3(@PathVariable("id") Long id){
       return paymentFeignService.getPaymentById(id);
    }
}

消费者80通过接口中的注解@FeignClient(value = "CLOUD-PAYMENT-SERVICE")来找到对应服务的URL,并且通过@GetMapping(value = "/payment/get/{id}")来找到对应的业务。无关消费者80接口的函数名(可以看到消费者函数名为getPaymentById3,而服务提供者为getPaymentById)。

 

posted @ 2020-07-31 14:02  JDLiao  阅读(363)  评论(0编辑  收藏  举报