首页 > 其他 > 详细

5、OpenFeign注意点

时间:2020-07-31 14:22:54      阅读:98      评论:0      收藏:0      [点我收藏+]

服务提供者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)。

 

5、OpenFeign注意点

原文:https://www.cnblogs.com/-jiandong/p/13409333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!