首页 > 其他 > 详细

(三)微服务消费者订单Module模块

时间:2020-04-27 12:25:26      阅读:70      评论:0      收藏:0      [点我收藏+]

技术分享图片

建cloud-consumer-order80

改POM

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.2.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>2.2.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

写YML

技术分享图片

主启动

技术分享图片

业务类

客户端消费者80 要调 微服务提供者8001,客户端应该只有controller。

entity

先去复制实体类,后面会抽取。
技术分享图片

Resttemplate

是什么

技术分享图片

官方使用

https://docs.spring.io/spring-framework/docs/5.2.2.RELEASE/javadoc-api/org/springframework/web/client/RestTemplate.html
技术分享图片

config配置类

ApplicationContextConfig
技术分享图片

controller

测试

启动两个服务
技术分享图片

http://localhost/consumer/payment/get/2

技术分享图片

不要忘记@RequestBody注解

输入:http://localhost/consumer/payment/create?serial=111
浏览器显示插入成功
技术分享图片

但是数据库有主键,serial为null
技术分享图片

原因:
没有加@RequestBody注解
技术分享图片

(三)微服务消费者订单Module模块

原文:https://www.cnblogs.com/sunyanblog/p/12785706.html

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