1、 报错信息
spring cloud resttemplate 相关报错 at com.controller.OrderController.getPaymentById2(OrderController.java:38)
2、 报错原因(可能)
80端口消费端里面的resttemplate 调用方法的路径需要在8001端口生产端里面有对应的路径,否则报上面的错误
3、 报错代码

package com.feng.springcloud.controller;import com.feng.springcloud.entities.CommonResult;
import com.feng.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;import javax.annotation.Resource;@RestController
@Slf4j
public class OrderController {//    public static final String PAYMENT_URL = "http://localhost:8001";public static final String PAYMENT_URL = "http://cloud-payment-service";
//    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";@Resourceprivate RestTemplate restTemplate;//http://localhost/consumer/payment/create?serial=tomorrow@GetMapping("/consumer/payment/create")public CommonResult<Payment> create(Payment payment){return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonResult.class);}//http://localhost/consumer/payment/get/2//@GetMapping("/consumer/payment/get/{id}")public CommonResult<Payment> getPaymentById(@PathVariable("id")Long id){return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class);}/*** at com.feng.springcloud.controller.OrderController.getPaymentById2(OrderController.java:38) ~[classes/:na]*  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_41]*  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_41]*    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_41]*    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_41]*     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.4.RELEASE.jar:5.2.4.RELEASE]*   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.4.RELEASE.jar:5.2.4.RELEASE]*   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]*  错误原因:*       80端口消费端里面的resttemplate 调用方法的路径需要在8001端口生产端里面有对应的路径,否则报上面的错误*/@GetMapping("/consumer/payment/get/{id}")public CommonResult getPaymentById2(@PathVariable("id")Long id){ResponseEntity<CommonResult> entity = restTemplate.getForEntity(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);if (entity.getStatusCode().is2xxSuccessful()){return entity.getBody();}else {return new CommonResult(444,"操作失败");}}
}

spring cloud resttemplate at com.controller.OrderController.getPaymentById2(OrderController.java:38)相关推荐

  1. Spring Cloud 2022.0.0 M1 发布:需Java 17、兼容Spring Boot 3

    各位小伙伴们,复工第一天,DD祝大家新年快乐!这个新年真的是好好休息了一下,文章也没有更,新闻也没怎么看.所以,新年第一篇就先带大家一起回顾下春节期间的一些新动态.从Spring官方信息看,这几天主要 ...

  2. Spring Cloud入门-Admin服务监控中心(Hoxton版本),java高级编程技术

    } 创建admin-client模块 这里我们创建一个admin-client模块作为客户端注册到admin-server. 在pom.xml中添加相关依赖: org.springframework. ...

  3. Spring Cloud Feign Clients 无需 Controller自动暴露Restful接口

    前言 在开发SpringCloud应用中,Feign作为声明式调用的事实标准极大的简化了Rest远程调用,提供了类本地化的调用方式.服务提供方的接口暴露方式是通过Controller暴露Restful ...

  4. Spring Cloud RestTemplate报错:java.lang.IllegalStateException: No instances available for xxx

    java.lang.IllegalStateException: No instances available for XXXX 一.问题复现 最近搭建springCloud项目,搭建Eureka,多 ...

  5. Spring Cloud Alibaba微服务项目中集成Redis实现分布式事务锁实践

    引言 我们知道同一个进程里面为了解决资源共享而不出现高并发的问题可以通过高并发编程解决,通过给变量添加volatile关键字实现线程间变量可见:通过synchronized关键字修饰代码块.对象或者方 ...

  6. 全网最全微服务架构—Spring Cloud详解,没有比这更详细的了!

    原文地址: https://blog.51cto.com/14570694/2482244 本文不是讲解如何使用Spring Cloud的教程,而是探讨Spring Cloud是什么,以及它诞生的背景 ...

  7. 重磅!腾讯正式开源 Spring Cloud Tencent,功能真心强大!

    你好,我是 Guide.在 手写一个简化版的 Spring Cloud!这篇文章中,我推荐了 Spring Cloud Tencent 这个项目,这篇文章就简单带着大家来看看腾讯开源的这款一站式微服务 ...

  8. 一篇深度长文带你理解Spring Cloud

    软件是有生命的,你做出来的架构决定了这个软件它这一生是坎坷还是幸福. 本文不是讲解如何使用Spring Cloud的教程,而是探讨Spring Cloud是什么,以及它诞生的背景和意义. 1 背景 2 ...

  9. 微服务架构集大成者—Spring Cloud (转载)

    软件是有生命的,你做出来的架构决定了这个软件它这一生是坎坷还是幸福. 本文不是讲解如何使用Spring Cloud的教程,而是探讨Spring Cloud是什么,以及它诞生的背景和意义. 1 背景 2 ...

最新文章

  1. 关于GUI_DOWNLOAD中下载excel等文档的乱码问题
  2. [转载] 信息系统项目管理挂靠合同(协议)范例1
  3. SorterBot-第1部分
  4. python标准数据库接口是_Python 数据库接口模块_python 数据库模块_python 数据库接口...
  5. .net开发中常用的第三方组件
  6. python装饰器详解-python 装饰器详解
  7. redmine-1.2.2安装代码评审插件
  8. the database profile could not loaded. Check log for details
  9. Windows10 64位系统安装EPLAN P8 2.6教程
  10. Xamarin入门一 环境准备
  11. java做抽奖小程序_随机抽奖小程序
  12. 通俗易懂的图解机器学习之机器学习概论
  13. Latex排版大括号让其左对齐
  14. 电脑编程入门需要学什么呢?
  15. 关于 Win10 下使用 IETester 的问题
  16. Codeforces--676A--Nicholas and Permutation
  17. dom4j解析xml碰到的问题
  18. apple pencil有买的必要吗?便宜的平替电容笔推荐
  19. 点线面的意义_对点线面的认知
  20. 简述网桥的特点_网桥的工作原理和特点是什么呢?

热门文章

  1. android mysql上传头像,Android自定义控件仿QQ编辑和选取圆形头像
  2. 4G模块CA7600操作笔记
  3. 8项技能9种武器 打造企业增长黑客
  4. 数字化智能物资仓储管理系统解决方案,智慧仓储管理系统
  5. Kolin 更优雅的封装ProgressDialog
  6. PyTorch手写字体识别MNIST
  7. 杰里之充电注意事项【篇】
  8. 深度|分析区块链系统的核心原理和概念
  9. 多模光纤带宽与传输速率
  10. Qt上位机软件串口通讯