皆非的万事屋

搭建【分布式新生电子报到系统】过程

根据要求需要把去年的新生电子报到系统由boot升级为cloud,把服务拆分做成分布式,这篇博客记录从0开始拆分并搭建分布式新生电子报到系统(不涉及业务源代码),并记录在使用技术栈和搭建过程中遇到的问题

主要技术栈选型

基础服务搭建

Nacos

Seata

[scode type="share"]为seata建数据库,导sql[/scode]

[scode type="share"]双击seata-server.bat启动[/scode]

Sentinel和Zipkin

[scode type="green"]到这里基本上四个服务就弄好了,在我自己的电脑上是开着4个黑窗口,3个监控页面,下面就进行项目搭建环节[/scode]



项目搭建

[scode type="share"]project名为electronic-registration-cloud,module名以erc-开头,包名都以zone.jiefei开头,项目配置均放入nacos配置中心[/scode]

父工程搭建

<?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>zone.jiefei</groupId>
    <artifactId>electronic-registration-cloud</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>erc-common</module>
        <module>erc-admin</module>
        <module>erc-gateway</module>
        <module>erc-openid</module>
        <module>erc-student</module>
        <module>erc-praise</module>
        <module>erc-data</module>
        <module>erc-student2</module>
        <module>erc-monitor</module>
    </modules>

    <!-- 统一管理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>
        <mybatis.plus.version>3.3.2</mybatis.plus.version>
        <log4jdbc.version>1.16</log4jdbc.version>
        <velocity.version>2.2</velocity.version>
        <lombok.version>1.16.18</lombok.version>
        <mysql.version>8.0.12</mysql.version>
        <druid.version>1.1.16</druid.version>
        <mybatis.spring.boot.version>1.3.2</mybatis.spring.boot.version>
        <swagger.version>2.9.2</swagger.version>
        <hutool.version>5.2.5</hutool.version>
    </properties>

    <!-- 子模块继承之后,提供作用:锁定版本+子module不用写groupId和version -->
    <dependencyManagement>
        <dependencies>
            <!-- Spring boot 2.2.4 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.4.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.2.0.RELEASE -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.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</artifactId>
                <version>${druid.version}</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>1.1.10</version>
            </dependency>

            <!--    mybatis plus相关  start  -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-generator</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity-engine-core</artifactId>
                <version>${velocity.version}</version>
            </dependency>

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <optional>true</optional>
            </dependency>

            <!--接口文档-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-annotations</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-models</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>1.5.21</version>
            </dependency>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-models</artifactId>
                <version>1.5.21</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${swagger.version}</version>
            </dependency>

            <!--工具包-->
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>${hutool.version}</version>
            </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>

基础模块搭建

[scode type="share"]自定义基础类模块erc-common[/scode]

[scode type="share"]网关模块erc-gateway[/scode]

[scode type="share"]监控模块erc-monitor[/scode]

[scode type="share"]准备工作[/scode]

结果展示

[scode type="share"]保持前端的代码不变,仅修改前端请求的接口地址为erc-gateway的地址[/scode]

大屏展示

附录

[scode type="yellow"]问题1:引入seata的项目启动报错,提示数据源方面的问题[/scode]

[scode type="yellow"]问题2:远程过程调用的方法提示请求体参数过多[/scode]

部署


[scode type="blue"]问题 公网ip与内网ip[/scode]

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »