SpringCloud无介绍快使用,新建cloud-api-commons公共模块module(九)

  • 问题背景
  • 项目搭建
  • Lyric: 告诉我印地安的传说


问题背景

从零开始学springcloud微服务项目
注意事项:

  • 约定 > 配置 > 编码
  • IDEA版本2021.1
  • 这个项目,我分了很多篇章,每篇文章一个操作步骤,目的是显得更简单明了
  • controller调service,service调dao
  • 项目源码以及sentinel安装包

项目搭建

1 新建公共模块module

springcloud mongodb配置 springcloud common 模块_java


2 选择JDK1.8

springcloud mongodb配置 springcloud common 模块_Cloud_02


3 输入module名:cloud-api-commons

springcloud mongodb配置 springcloud common 模块_java_03


4 引入pom依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springcloud2022</artifactId>
        <groupId>com.yg</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-api-commons</artifactId>

    <dependencies>
        <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>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.1.0</version>
        </dependency>
    </dependencies>

</project>

5 在cloud-consumer-order80和cloud-provider-payment8001的pom里面添加公共依赖

<!-- 引入自己定义的api通用包,可以使用Payment支付Entity -->
        <dependency>
            <groupId>com.yg</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>

6 把公共代码复制到cloud-api-commons模块,删除cloud-consumer-order80和cloud-provider-payment8001的公共代码

springcloud mongodb配置 springcloud common 模块_java_04


7 整体目录结构

springcloud mongodb配置 springcloud common 模块_spring_05

8 使用maven进行install构建cloud-api-commons

springcloud mongodb配置 springcloud common 模块_Cloud_06

9 启动cloud-consumer-order80和cloud-provider-payment8001使用postman测试:http://localhost/consumer/payment/create?serial=ooo

springcloud mongodb配置 springcloud common 模块_Cloud_07


springcloud mongodb配置 springcloud common 模块_Cloud_08

SpringCloud无介绍快使用,Seata处理分布式事务(二十五)SpringCloud无介绍快使用,sentinel服务熔断功能(二十四)SpringCloud无介绍快使用,sentinel注解@SentinelResource的基本使用(二十三)SpringCloud无介绍快使用,sentinel热点key限流与系统规则的基本使用(二十二)SpringCloud无介绍快使用,sentinel熔断降级和限流的基本使用(二十一)SpringCloud无介绍快使用,Nacos集群和Nginx代理(二十)SpringCloud无介绍快使用,nacos配置中心的基本使用(十九)SpringCloud无介绍快使用,nacos注册中心的基本使用(十八)SpringCloud无介绍快使用,gateway通过微服务名实现动态路由(十七)SpringCloud无介绍快使用,gateway的基本使用(十六)SpringCloud无介绍快使用,Ribbon负载均衡工具与OpenFeign的使用(十五)SpringCloud无介绍快使用,使用Zookeeper替换Eureka服务注册与发现(十四)SpringCloud无介绍快使用,服务发现Discovery和Eureka自我保护(十三)SpringCloud无介绍快使用,集群cloud-provider-payment8002搭建(十二)SpringCloud无介绍快使用,集群Eureka服务注册中心cloud-eureka-server7002搭建(十一)SpringCloud无介绍快使用,单机Eureka服务注册中心cloud-eureka-server7001搭建(十)SpringCloud无介绍快使用,新建cloud-api-commons公共模块module(九)SpringCloud无介绍快使用,新建子module消费者订单模块(八)SpringCloud无介绍快使用,热部署devtools配置(七)SpringCloud无介绍快使用,子module提供者支付微服务业务开发(六)SpringCloud无介绍快使用,新建子module提供者支付微服务yml整合和新建启动类(五)SpringCloud无介绍快使用,新建子module提供者支付微服务pom整合(四)SpringCloud无介绍快使用,springcloud父工程pom文件整理(三)SpringCloud无介绍快使用,IDEA新建springcloud父工程(二)SpringCloud无介绍快使用,与Spingboot之间的兼容版本选择(一)