SpringCloud微服务项目搭建(最新版本选择)

发布于:2022-11-16 ⋅ 阅读:(1734) ⋅ 点赞:(2)

小聊: 本次小白为大家带来SpringCloud项目工程的搭建详细步骤,其实新建项目并不难,对于新手来说有疑惑的就是有关pom.xml的依赖导入什么以及依赖的版本选择问题。所以,接下来小白灰被大家带来目前官方最新适配的SpringCloudAlibaba项目的依赖选择,当然小白不是只讲最终的配置结果,而是会提示大家如何去选择项目版本,也就是说,大家可以随时参照,以供以后也可以选择最新适合的依赖版本组合。所以如果只想要SpringCloud微服务的话也可以。小白开发部署过SpringCloudAlibaba微服务项目,所以没问题。

注意:小白这里强调的是最新最匹配的依赖版本组合,主要是包含SpringCloudAlibaba系列、SpringCloud和SpringBoot的版本组合。因为某个技术的最新并不一定可以匹配其它技术的最新版本,所以才是“最适配”的组合推荐。是根根据官网推荐的,所以大家放心,其实很简单,直接看官网版本就好了,下面我也会贴出对应的官网推荐搭配的网址以及内容。


1. 各技术相关网址

1)SpringBoot相关

SpringBoot github版本地址:https://github.com/spring-projects/spring-boot/releases

SpringBoot官网地址:https://spring.io/projects/spring-boot/


2)SpringCloud相关

SpringCloud官网地址:https://spring.io/projects/spring-cloud


3)Spring Cloud Alibaba相关

SpringCloudAlibaba github版本地址:https://github.com/alibaba/spring-cloud-alibaba/releases

SpringCloud官网地址:https://spring.io/projects/spring-cloud-alibaba/


2. SpringCloud微服务项目适配版本推荐

主要是和Springboot的适配,因为大家都知道Springboot是“生产化”的spring项目,自动管理整合了很多技术依赖的版本,所以我们这里只需要把SpringCloud和SpringBoot对应上就好了。

官网推荐网址:https://spring.io/projects/spring-cloud#overview

在这里插入图片描述


2.1. 更详细的版本对应查看方法

https://start.spring.io/actuator/info

这个是一个Json字符串网页,使用在线Json格式化工具查看:http://www.jsons.cn/jsoncheck/

{
    "git": {
        "branch": "d8ae4573f747cfd71693fb5a41916681b1126aa7", 
        "commit": {
            "id": "d8ae457", 
            "time": "2022-11-12T16:35:20Z"
        }
    }, 
    "build": {
        "version": "0.0.1-SNAPSHOT", 
        "artifact": "start-site", 
        "versions": {
            "spring-boot": "2.7.5", 
            "initializr": "0.20.0-SNAPSHOT"
        }, 
        "name": "start.spring.io website", 
        "time": "2022-11-12T16:38:14.902Z", 
        "group": "io.spring.start"
    }, 
    "bom-ranges": {
        "codecentric-spring-boot-admin": {
            "2.4.3": "Spring Boot >=2.3.0.M1 and <2.5.0-M1", 
            "2.5.6": "Spring Boot >=2.5.0.M1 and <2.6.0-M1", 
            "2.6.8": "Spring Boot >=2.6.0.M1 and <2.7.0-M1", 
            "2.7.4": "Spring Boot >=2.7.0.M1 and <3.0.0-M1", 
            "3.0.0-M4": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
        }, 
        "solace-spring-boot": {
            "1.1.0": "Spring Boot >=2.3.0.M1 and <2.6.0-M1", 
            "1.2.2": "Spring Boot >=2.6.0.M1 and <3.0.0-M1"
        }, 
        "solace-spring-cloud": {
            "1.1.1": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", 
            "2.1.0": "Spring Boot >=2.4.0.M1 and <2.6.0-M1", 
            "2.3.2": "Spring Boot >=2.6.0.M1 and <3.0.0-M1"
        }, 
        "spring-cloud": {
            "Hoxton.SR12": "Spring Boot >=2.2.0.RELEASE and <2.4.0.M1", 
            "2020.0.6": "Spring Boot >=2.4.0.M1 and <2.6.0-M1", 
            "2021.0.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-M3", 
            "2021.0.0-M3": "Spring Boot >=2.6.0-M3 and <2.6.0-RC1", 
            "2021.0.0-RC1": "Spring Boot >=2.6.0-RC1 and <2.6.1", 
            "2021.0.5": "Spring Boot >=2.6.1 and <3.0.0-M1", 
            "2022.0.0-M1": "Spring Boot >=3.0.0-M1 and <3.0.0-M2", 
            "2022.0.0-M2": "Spring Boot >=3.0.0-M2 and <3.0.0-M3", 
            "2022.0.0-M3": "Spring Boot >=3.0.0-M3 and <3.0.0-M4", 
            "2022.0.0-M4": "Spring Boot >=3.0.0-M4 and <3.0.0-M5", 
            "2022.0.0-M5": "Spring Boot >=3.0.0-M5 and <3.0.0-RC1", 
            "2022.0.0-RC1": "Spring Boot >=3.0.0-RC1 and <3.1.0-M1"
        }, 
        "spring-cloud-azure": {
            "4.3.0": "Spring Boot >=2.5.0.M1 and <2.7.0-M1", 
            "4.4.1": "Spring Boot >=2.7.0-M1 and <3.0.0-M1", 
            "6.0.0-beta.3": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
        }, 
        "spring-cloud-gcp": {
            "2.0.11": "Spring Boot >=2.4.0-M1 and <2.6.0-M1", 
            "3.4.0": "Spring Boot >=2.6.0-M1 and <3.0.0-M1"
        }, 
        "spring-cloud-services": {
            "2.3.0.RELEASE": "Spring Boot >=2.3.0.RELEASE and <2.4.0-M1", 
            "2.4.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", 
            "3.3.0": "Spring Boot >=2.5.0-M1 and <2.6.0-M1", 
            "3.4.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1", 
            "3.5.0": "Spring Boot >=2.7.0-M1 and <3.0.0-M1"
        }, 
        "spring-shell": {
            "2.1.3": "Spring Boot >=2.7.0 and <3.0.0-M1", 
            "3.0.0-M2": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
        }, 
        "vaadin": {
            "14.9.1": "Spring Boot >=2.1.0.RELEASE and <2.6.0-M1", 
            "23.2.7": "Spring Boot >=2.6.0-M1 and <2.8.0-M1"
        }, 
        "wavefront": {
            "2.0.2": "Spring Boot >=2.1.0.RELEASE and <2.4.0-M1", 
            "2.1.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", 
            "2.2.2": "Spring Boot >=2.5.0-M1 and <2.7.0-M1", 
            "2.3.0": "Spring Boot >=2.7.0-M1 and <3.0.0-M1"
        }
    }, 
    "dependency-ranges": {
        "native": {
            "0.9.0": "Spring Boot >=2.4.3 and <2.4.4", 
            "0.9.1": "Spring Boot >=2.4.4 and <2.4.5", 
            "0.9.2": "Spring Boot >=2.4.5 and <2.5.0-M1", 
            "0.10.0": "Spring Boot >=2.5.0-M1 and <2.5.2", 
            "0.10.1": "Spring Boot >=2.5.2 and <2.5.3", 
            "0.10.2": "Spring Boot >=2.5.3 and <2.5.4", 
            "0.10.3": "Spring Boot >=2.5.4 and <2.5.5", 
            "0.10.4": "Spring Boot >=2.5.5 and <2.5.6", 
            "0.10.5": "Spring Boot >=2.5.6 and <2.5.9", 
            "0.10.6": "Spring Boot >=2.5.9 and <2.6.0-M1", 
            "0.11.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-RC1", 
            "0.11.0-M2": "Spring Boot >=2.6.0-RC1 and <2.6.0", 
            "0.11.0-RC1": "Spring Boot >=2.6.0 and <2.6.1", 
            "0.11.0": "Spring Boot >=2.6.1 and <2.6.2", 
            "0.11.1": "Spring Boot >=2.6.2 and <2.6.3", 
            "0.11.2": "Spring Boot >=2.6.3 and <2.6.4", 
            "0.11.3": "Spring Boot >=2.6.4 and <2.6.6", 
            "0.11.5": "Spring Boot >=2.6.6 and <2.7.0-M1", 
            "0.12.0": "Spring Boot >=2.7.0-M1 and <2.7.1", 
            "0.12.1": "Spring Boot >=2.7.1 and <3.0.0-M1"
        }, 
        "okta": {
            "1.4.0": "Spring Boot >=2.2.0.RELEASE and <2.4.0-M1", 
            "1.5.1": "Spring Boot >=2.4.0-M1 and <2.4.1", 
            "2.0.1": "Spring Boot >=2.4.1 and <2.5.0-M1", 
            "2.1.6": "Spring Boot >=2.5.0-M1 and <3.0.0-M1"
        }, 
        "mybatis": {
            "2.1.4": "Spring Boot >=2.1.0.RELEASE and <2.5.0-M1", 
            "2.2.2": "Spring Boot >=2.5.0-M1"
        }, 
        "camel": {
            "3.5.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", 
            "3.10.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1", 
            "3.13.0": "Spring Boot >=2.5.0.M1 and <2.6.0-M1", 
            "3.17.0": "Spring Boot >=2.6.0.M1 and <2.7.0-M1", 
            "3.19.0": "Spring Boot >=2.7.0.M1 and <3.0.0-M1"
        }, 
        "picocli": {
            "4.6.3": "Spring Boot >=2.4.0.RELEASE and <3.0.0-M1"
        }, 
        "open-service-broker": {
            "3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", 
            "3.3.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", 
            "3.4.1": "Spring Boot >=2.5.0-M1 and <2.6.0-M1", 
            "3.5.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1"
        }
    }
}

2.2. 建议使用

只是只用SpringBoot的话用最新的。

要是使用SpringCloud微服务项目的话,SpringCloud用最新的,SpringBoot找对应最适合的版本。


3. Spring Cloud Alibaba 产品版本推荐

Spring Cloud Alibaba的依赖版本里面是集成了Alibaba自己的有关于SpringCloud开发框架的版本集合,包括nacos、seata、sentinel、rocketmq等,使用这些产品的时候要和SpringCloud版本对应上,所以要想使用最新的SpringCloudAlibaba产品就需要先选择SpringCloudAlibaba依赖的最新版本,在去选择SpringCloud以及SpringBoot的版本。(因为SpringCloudAlibaba肯定没它们更新快呀)

官方版本说明网址:
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E

以下为官方原话,我直接拿过来了哦~


3.1. 毕业版本依赖关系(推荐使用)

由于 Spring Boot 2.4+ 和以下版本之间变化较大,目前企业级客户老项目相关 Spring Boot 版本仍停留在 Spring Boot 2.4 以下,为了同时满足存量用户和新用户不同需求,社区以 Spring Boot 2.4 为分界线,同时维护 2.2.x 和 2021.x 两个分支迭代。

1)2021.x 分支

适配 Spring Boot 2.4,Spring Cloud 2021.x 版本及以上的 Spring Cloud Alibaba 版本按从新到旧排列如下表(最新版本用*标记): (注意,该分支 Spring Cloud Alibaba 版本命名方式进行了调整,未来将对应 Spring Cloud 版本,前三位为 Spring Cloud 版本,最后一位为扩展版本,比如适配 Spring Cloud 2021.0.1 版本对应的 Spring Cloud Alibaba 第一个版本为:2021.0.1.0,第个二版本为:2021.0.1.1,依此类推)

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2021.0.4.0* Spring Cloud 2021.0.4 2.6.11
2021.0.1.0 Spring Cloud 2021.0.1 2.6.3
2021.1 Spring Cloud 2020.0.1 2.4.2

2)2.2.x 分支

适配 Spring Boot 为 2.4,Spring Cloud Hoxton 版本及以下的 Spring Cloud Alibaba 版本按从新到旧排列如下表(最新版本用*标记):

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2.2.9.RELEASE* Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.8.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.7.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.6.RELEASE Spring Cloud Hoxton.SR9 2.3.2.RELEASE
2.2.1.RELEASE Spring Cloud Hoxton.SR3 2.2.5.RELEASE
2.2.0.RELEASE Spring Cloud Hoxton.RELEASE 2.2.X.RELEASE
2.1.4.RELEASE Spring Cloud Greenwich.SR6 2.1.13.RELEASE
2.1.2.RELEASE Spring Cloud Greenwich 2.1.X.RELEASE
2.0.4.RELEASE(停止维护,建议升级) Spring Cloud Finchley 2.0.X.RELEASE
1.5.1.RELEASE(停止维护,建议升级) Spring Cloud Edgware 1.5.X.RELEASE

3.2. 组件版本关系

每个 Spring Cloud Alibaba 版本及其自身所适配的各组件对应版本如下表所示(注意,Spring Cloud Dubbo 从 2021.0.1.0 起已被移除出主干,不再随主干演进):

Spring Cloud Alibaba Version Sentinel Version Nacos Version RocketMQ Version Dubbo Version Seata Version
2.2.9.RELEASE 1.8.5 2.1.0 4.9.4 ~ 1.5.2
2021.0.4.0 1.8.5 2.0.4 4.9.4 ~ 1.5.2
2.2.8.RELEASE 1.8.4 2.1.0 4.9.3 ~ 1.5.1
2021.0.1.0 1.8.3 1.4.2 4.9.2 ~ 1.4.2
2.2.7.RELEASE 1.8.1 2.0.3 4.6.1 2.7.13 1.3.0
2.2.6.RELEASE 1.8.1 1.4.2 4.4.0 2.7.8 1.3.0
2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE 1.8.0 1.4.1 4.4.0 2.7.8 1.3.0
2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE 1.8.0 1.3.3 4.4.0 2.7.8 1.3.0
2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE 1.7.1 1.2.1 4.4.0 2.7.6 1.2.0
2.2.0.RELEASE 1.7.1 1.1.4 4.4.0 2.7.4.1 1.0.0
2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE 1.7.0 1.1.4 4.4.0 2.7.3 0.9.0
2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE 1.6.3 1.1.1 4.4.0 2.7.3 0.7.1

4. 示例:新建最新SpringCloudAlibaba微服务项目

哇哦,终于讲到这里来了……这里以带有SpringCloudAlibaba产品的SpringCloud微服务最新最适配的版本为例,如果只是想要SpringCloud微服务项目可以根据上面的官方,推荐然后再参考下面示例进行配置搭建。


4.1. 新建父工程project,使用最简单的Maven项目

1)选择Maven项目的初始框架,jdk版本,取名,指定位置

初始框架:org.apache.maven.archetypes:maven-archetype-site

jdk版本:jkd1.8

名字:SpringCloud2022

在这里插入图片描述


2)打开File ——> Settings, 搜索Maven,指定自己安装Maven路径方便导入pom坐标的文件

在这里插入图片描述


3)用准备好的父工程项目的 pom.xml 文件,指定已经准备好的 SpringCloud 版本主要环境,以下是准备好的 pom.xml 文件内容

<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.byy.springbloud</groupId>
    <artifactId>SpringCloud2022</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>user-service</module>
    </modules>
    <!-- 修改打包方式 -->
    <packaging>pom</packaging>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!-- 2022.11.16 SpringCloudAlibaba2021.x 最新适配版3SpringXXX搭配 -->
        <spring-boot.version>2.6.11</spring-boot.version>
        <spring-cloud.version>2021.0.4</spring-cloud.version>
        <spring-cloud-alibaba.version>2021.0.4.0</spring-cloud-alibaba.version>
        <!-- mybatis-plus 选择版本适配spring-boot -->
        <mybatis-plus.version>3.5.1</mybatis-plus.version>
        <!-- 2022.11.16 SpringCloudAlibaba2.2.x 最新适配版3SpringXXX搭配 -->
        <!--    <spring-boot.version>2.3.12.RELEASE</spring-boot.version>-->
        <!--    <spring-cloud.version>Hoxton.SR12</spring-cloud.version>-->
        <!--    <spring-cloud-alibaba.version>2.2.9.RELEASE</spring-cloud-alibaba.version>-->
        <!--    <mybatis-plus.version>3.4.2</mybatis-plus.version>-->
        <mysql.version>8.0.22</mysql.version>
        <fastjson.version>2.0.18</fastjson.version>
        <junit.version>4.13.2</junit.version>
        <lombok.version>1.18.24</lombok.version>
        <log4j.version>1.2.17</log4j.version>
    </properties>

    <!--  因为是总项目 所以用dependencyManagement来管理;其他的子项目就不会来管理版本了了 可以直接引用 -->
    <dependencyManagement>
        <dependencies>
            <!-- springBoot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <!-- type和scope标签:让子model可以多继承父model -->
                <!-- <type></type> 里的值默认值是jar表示引入的是jar包,这里使用的是pom表示导入的是父模块; -->
                <!-- <scope></scope>中的值import代表把父模块中的jar包导入进来,不过需要注意的是<scope>import</scope>, -->
                <!-- 这种方式只能用在<dependencyManagement></dependencyManagement>中。 -->
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- springCloudAlibaba -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- mysql驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <!-- mybatis-plus -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
            <!-- Java对象和JSON相互转换 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${fastjson.version}</version>
            </dependency>
            <!-- JavaBean 注解构建 -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <optional>true</optional>
            </dependency>
            <!-- 测试 -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
            </dependency>
            <!-- 日志 -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

4.2. 新建子项目工程

1)选择新建子模块Maven项目

在这里插入图片描述

哦,说一下,父工程里的src目录没什么用删了,碍眼,还有 .idea 目录隐藏掉了,也它没什么事。怎么隐藏去 Settings ——> Editor ——> File Types 中,点击 “Ignored Files and Folders” 分栏,里面有其他隐藏文件的格式,照着写,比如添加 *.idea

在这里插入图片描述


2)配置Maven子项目设置

这里最好选择Maven项目,不要选什么Spring Initializer,这个确实是用来新建 SpringBoot/SpringCloud 项目的,但是它不会默认自己是子模块的,换句话讲,它会是一个独立的项目,只不过在我们之前创建的父工程目录里面而已,却不会自动配置好去继承父工程的pom坐标,我们还得自己去父工程中加子模块 <modules> 标签指定,麻烦。最好选择 Maven项目,默认会配置成子模块,而且pom.xml里面没什么依赖坐标,想加什么随时加。

在这里插入图片描述

这里的框架我选了 org.apache.maven.archetypes:maven-archetype-webapp,这是一个Web框架,我只是看中了它会帮我把Web项目目录结构都建好,当然如果不是Web功能模块的话选别的框架就好了。总之最后都可以自己改的,不要太纠结。


3)修改子模块user-serivice的pom.xml配置

嘛,这个得按照自己的子项目需求导入依赖,我下面写多一点,不一定会用到那么多,你可以作参考。

<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/maven-v4_0_0.xsd">
    <parent>
        <artifactId>SpringCloud2022</artifactId>
        <groupId>com.byy.springbloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <!-- 模块名称 -->
    <artifactId>user-service</artifactId>

    <!-- 注意,子项目模块就是 dependencies 了,是真正需要导入包的,版本则不需要指定 -->
    <dependencies>
        <!-- Web开发 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- SpringBoot应用的监控 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- SpringBoot测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!-- springboot统一封装的消息中间件框架 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <!-- mongodb -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <!-- redis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--引入es的RestHighLevelClient依赖-->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
        </dependency>
        <!-- nacos客户端依赖包 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!--nacos的配置管理依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <!-- 配置sentinel规则持久化,引入sentinel监听nacos的依赖 -->
        <!-- 为了减少开发的复杂程度,Sentinel 对大部分的主流框架做了适配, -->
        <!-- 例如 SpringMVC、WebFlux、Dubbo、Spring Cloud、RocketMQ 等等。 -->
        <!-- 我们只需要引入对应的 sentinel-apache-xxx-adapter 依赖,即可方便地整合 Sentinel。 -->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-nacos</artifactId>
        </dependency>
        <!-- sentinel微服务保护 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <!-- 配置spring-webmvc集成sentinel,做web监控 -->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-spring-webmvc-adapter</artifactId>
        </dependency>
        <!-- gateway网关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <!-- seata全局事务控制 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
        </dependency>
        <!-- openfeign RPC远程调用 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <!-- kafka 消息中间件 -->
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <!-- springboot热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!-- ojdbc8 -->
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- Java对象和JSON相互转换 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <!-- JavaBean 注解构建 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- 测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!-- 日志 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
    </dependencies>

    <!-- 每个子项目可单独打包然后分发到各自服务器部署 -->
    <build>
        <!-- 文件项目打包名字,不设置默认是artifactId与version拼接的结果 -->
        <finalName>user-service</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 热部署配置需添加以下configuration,不加该配置可能不会生效。不需要热部署可以去掉 -->
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

好了,一个微服务项目基本配置完成,多个子工程的话添再加就好了。


随笔

在这里插入图片描述

本文含有隐藏内容,请 开通VIP 后查看