Spring Cloud Alibaba学习项目环境搭建

版本说明

首先这三者版本对应关系参照官网地址版本说明,如下所示

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2021.0.1.0 Spring Cloud 2021.0.1 2.6.3
2.2.7.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2021.1 Spring Cloud 2020.0.1 2.4.2
2.2.6.RELEASE Spring Cloud Hoxton.SR9 2.3.2.RELEASE
2.1.4.RELEASE Spring Cloud Greenwich.SR6 2.1.13.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.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

本学习项目采用Spring Cloud Alibaba 2.2.7.RELEASE版本

父模块搭建

用于统一项目Spring Boot、Spring Cloud、Spring Cloud Alibaba版本。

先使用IDEA新键一个Empty Project,作为项目根目录。然后此目录下新键模块,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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.wangtao</groupId>
  <artifactId>springcloud-alibaba-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <spring-boot.version>2.3.12.RELEASE</spring-boot.version>
    <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
    <spring-cloud-alibaba.version>2.2.7.RELEASE</spring-cloud-alibaba.version>

    <!-- 使用新版seata -->
    <seata.version>1.6.1</seata.version>
    <mybatis-plus.version>3.5.3.1</mybatis-plus.version>

    <!-- 内置插件 -->
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- 核心依赖 -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <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>

      <!-- 此版本和seata服务端保持一致 -->
      <dependency>
        <groupId>io.seata</groupId>
        <artifactId>seata-spring-boot-starter</artifactId>
        <version>${seata.version}</version>
      </dependency>

      <!-- 次要依赖 -->
      <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>${mybatis-plus.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${maven-compiler-plugin.version}</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>${maven-resources-plugin.version}</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>${maven-jar-plugin.version}</version>
        </plugin>

        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>${spring-boot.version}</version>
          <executions>
            <execution>
              <id>repackage</id>
              <goals>
                <goal>repackage</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

其它项目继承该模块即可,举例如下

<parent>
    <groupId>com.wangtao</groupId>
    <artifactId>springcloud-alibaba-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../springcloud-alibaba-parent/pom.xml</relativePath>
</parent>

项目源代码

项目地址

posted on 2022-05-13 22:06  wastonl  阅读(254)  评论(0编辑  收藏  举报