• 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)。

     

  • 相关阅读:
    页面访问权限控制
    购物车效果
    content: "e600"
    wf-删除所选
    event.target.getAttribute('id')
    css content
    mysql 浏览器submit中文, shell乱码
    导入导出
    mysql 标点符号
    mysql json
  • 原文地址:https://www.cnblogs.com/-jiandong/p/13409333.html
Copyright © 2020-2023  润新知