关于springboot:分布式架构

3次阅读

共计 3508 个字符,预计需要花费 9 分钟才能阅读完成。

1 分布式架构设计

1.1 传统我的项目架构设计问题

阐明: 因为单体我的项目将所有的模块都写到了一起, 未来如果其中一个模块呈现了问题, 将导致整个我的项目不能失常的运行.

1.2 分布式介绍

因为传统我的项目导致各个模块之间的耦合性较高. 所以须要采纳分布式的思维将我的项目进行拆分.
核心理念: 化整为零将我的项目依照某些特定的规定进行拆分.

1.2.1 依照功能模块拆分

1.2.2 依照层级拆分

2 分布式思维带来的问题

2.1 分布式思维 jar 包如何保护?

2.2 分布式思维中工具 api 如何治理?

3 创立父级工程

3.1 创立我的项目 一般 maven 我的项目

3.2 编辑 pom.xml 文件

<!-- 定义父级工程打包类型 -->
<packaging>pom</packaging>

<!--1. 引入 springBoot 父级我的项目 -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<!--2. 引入属性的配置 -->
<properties>
    <java.version>1.8</java.version>
    <!-- 跳过测试类打包 -->
    <skipTests>true</skipTests>
</properties>

<!--3. 在父级我的项目中增加 jar 包文件 -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- 引入插件 lombok 主动的 set/get/ 构造方法插件  -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>

    <!-- 引入数据库驱动 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!--springBoot 数据库连贯  -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <!--spring 整合 mybatis-plus -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.2.0</version>
    </dependency>

    <!--springBoot 整合 JSP 增加依赖  -->
    <!--servlet 依赖 -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>

    <!--jstl 依赖 -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <!-- 使 jsp 页面失效 -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

    <!-- 反对热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>

    <!-- 增加 httpClient jar 包 -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
    </dependency>

    <!-- 引入 dubbo 配置 -->
    <!--<dependency>
        <groupId>com.alibaba.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>0.2.0</version>
    </dependency>-->

    <!-- 增加 Quartz 的反对 -->
   <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-quartz</artifactId>
    </dependency>-->

    <!-- 引入 aop 反对 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

    <!--spring 整合 redis -->
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
    </dependency>
</dependencies>

<!-- 父级工程只是我的项目的管理者不会在其中编辑代码 所以不要增加 build-->

</project>

3.3 编辑工具 API 我的项目 jt-common

3.3.1 创立我的项目 - 一般 maven 我的项目

3.4 创立 jt-manage 我的项目

3.4.1 编辑 pom. 文件

<!-- 指定打包形式 -->
<packaging>war</packaging>
<!-- 指定父级我的项目 -->
<parent>
    <artifactId>jt</artifactId>
    <groupId>com.jt</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<!--2. 增加依赖信息 -->
<dependencies>
    <dependency>
        <groupId>com.jt</groupId>
        <artifactId>jt-common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

<!--3. 增加插件 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

</project>

正文完
 0