SpringCloud/Alibaba 聚合项目搭建

1. 创建父工程

1.1 New Project

在这里插入图片描述

1.2聚合总父工程名字

在这里插入图片描述

1.3 Maven 版本

在这里插入图片描述

1.4 字符编码

在这里插入图片描述

1.5 注解生效激活

在这里插入图片描述

1.6 Java编译版本选择

在这里插入图片描述

1.7 File Type 过滤

在这里插入图片描述

2. 父工程 POM

2.1 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.wpp</groupId>
  <artifactId>springcloud</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>


<!--  统一管理 jar 包版本-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <junit.version>4.12</junit.version>
    <log4j.version>1.2.17</log4j.version>
    <lombok.version>1.16.18</lombok.version>
    <mysql.version>5.1.47</mysql.version>
    <druid.version>1.1.16</druid.version>
    <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
  </properties>

<!--  子模块继承之后,提供作用:锁定版本、子 module 不用写 groupId 和 version-->
  <dependencyManagement>
    <dependencies>
      <!--  spring boot 2.2.2    -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.2.2.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    <!--   spring cloud Hoxton.SR1   -->
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Hoxton.SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

      <!--   spring cloud alibaba 2.1.0.RELEASE   -->
      <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.1.0.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>${druid.version}</version>
      </dependency>

    </dependencies>
  </dependencyManagement>


  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>

        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>

      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <configuration>
          <locales>en,fr</locales>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

2.2 dependencyManagement 与 dependencies 区别

   像上面那样做的好处就是:如果有多个子项目都引用同一个依赖,则可以避免在每个使用的子项目里都声明一个版本号,这样当想升级或切换到另一个版本时,只需要在顶层父容器里更新,而不需要一个一个子项目的修改;另外如果某个子项目需要另外的一个版本,只需要声明 version 就可。

  • dependencyManagement 里只是声明依赖,并不实现,因此子项目需要显示的声明需要用的依赖。
  • 如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且 version 和 scope 都读取自父pom;
  • 如果子项目中指定了版本号,那么会使用子项目中指定的 jar 版本。

3. 验证 maven 与 idea 的整合

在这里插入图片描述
结果为:BUILD SUCCESS,说明已整合完毕
在这里插入图片描述

4. 添加子 Module

4.1 使用 springboot 模板方式

在这里插入图片描述
在这里插入图片描述

4.2 修改子 module 的 pom 文件

主要修改<parent></parent>标签内容,即父类的坐标。<dependencies></dependencies> 标签中的 jar 包坐标(继承父类不需要写版本号)

<parent>
        <artifactId>springcloud</artifactId>
        <groupId>com.wpp</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>order</artifactId>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </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-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

    </dependencies>

4.3 修改父 pom 文件

	<modules>
        <module>order</module>
    </modules>

4.4 启动测试

Spring Cloud是一套用于构建微服务架构的开源框架,而Spring Cloud AlibabaSpring Cloud的衍生项目,通过集成阿里巴巴的技术栈,提供更多强大的功能和解决方案。 在《Spring Cloud / Alibaba 微服务架构实战》这本书中,作者深入浅出地介绍了如何使用Spring Cloud Alibaba构建和部署微服务架构。 首先,作者从微服务的基本概念开始讲解,阐述了微服务架构相对于传统单体架构的优势。然后介绍了Spring Cloud Alibaba的特点和使用场景。 接着,作者详细介绍了微服务架构中常用的组件和技术,如服务注册与发现、负载均衡、熔断限流、分布式配置中心、消息队列等。通过实际案例,演示了如何使用Spring Cloud Alibaba的组件和技术来构建高可用、可扩展、易维护的微服务应用。 此外,作者还讲解了微服务架构中的分布式事务、服务网关、监控和日志等关键问题,并提供了解决方案和最佳实践。 在书的最后,作者总结了使用Spring Cloud Alibaba构建微服务架构的几点重要原则和注意事项,帮助读者更好地理解和应用这些技术。 总的来说,这本书详细解释了Spring Cloud Alibaba的各个组件和技术,提供了实战经验和案例,帮助读者从零开始构建微服务架构。无论是初学者还是有一定经验的开发者,都可以从中获得宝贵的知识和经验,提升自己在微服务领域的能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值