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

建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

测试

启动两个服务

扫描二维码关注公众号,回复: 11137639 查看本文章

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

不要忘记@RequestBody注解

输入:http://localhost/consumer/payment/create?serial=111
浏览器显示插入成功

但是数据库有主键,serial为null

原因:
没有加@RequestBody注解

猜你喜欢

转载自www.cnblogs.com/sunyanblog/p/12785706.html
今日推荐