赞
踩
其实Spring Cloud是在Spring Boot基础上构建的,用于快速构建分布式系统的通用模式的工具集。
他的特点:约定优于配置。组件丰富,功能齐全。SpringCloud为微服务。列如Euerk架构提供了非常完整的支持。列如配置管理、服务发现、断路器、微服务网关等。
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>com.huangmount</groupId>
- <artifactId>HuangMount</artifactId>
- <version>3.6.3</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <modules>
- <module>huangmount-api-system</module>
- </modules>
-
- <artifactId>huangmount-api</artifactId>
- <packaging>pom</packaging>
-
- <description>
- huangmount-api系统接口
- </description>
-
- </project>

服务发现与注册:Spring Cloud阿里巴巴集成了Nacos,一个强大的服务发现和注册中心。通过Nacos,微服务应用可以实现动态的服务注册和发现,以便服务之间可以相互调用。
配置管理:Nacos还提供了配置管理功能,允许开发者集中管理微服务的配置信息,并实现动态配置刷新。
服务容错保护:通过集成Sentinel,Spring Cloud阿里巴巴可以对微服务进行流量控制、熔断降级和系统负载保护,防止因服务故障或异常导致整个系统崩溃。
消息驱动:Spring Cloud阿里巴巴支持集成RocketMQ,一个消息队列,使得微服务之间可以进行异步通信和事件驱动的交互。
多个事务:通过Seata,Spring Cloud阿里巴巴可以实现多个事务的管理和协调,保证多个微服务之间的数据操作的一致性和可靠性。
RPC 通信:虽然 Dubbo 不是 Spring Cloud Obama 的蜡烛组件,但它是一个高性能的 RPC 框架,也可以方便地与 Spring Cloud Ali 集成,提供快速、高效的微服务间通信。
Nacos(Naming and Configuration Service):
Sentinel:
RocketMQ:
Seata:
Dubbo(可选,不是Spring Cloud Alibaba的独有组件):
这些组件为构建微服务应用提供了一系列的解决方案,涵盖了服务发现、配置管理、容错保护、消息驱动、分布式事务等关键功能。使用这些组件,开发者可以更方便地构建复杂的微服务应用,并具备了更好的弹性和可靠性。
- <?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.huangmount</groupId>
- <artifactId>HuangMount</artifactId>
- <version>3.6.3</version>
-
- <name>huangmount</name>
- <description>alibaba微服务系统</description>
-
- <properties>
- <huangmount.version>3.6.3</huangmount.version>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- <spring-boot.version>2.7.13</spring-boot.version>
- <spring-cloud.version>2021.0.8</spring-cloud.version>
- <spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
- <spring-boot-admin.version>2.7.10</spring-boot-admin.version>
- <swagger.fox.version>3.0.0</swagger.fox.version>
- <swagger.core.version>1.6.2</swagger.core.version>
- <tobato.version>1.27.2</tobato.version>
- <kaptcha.version>2.3.3</kaptcha.version>
- <pagehelper.boot.version>1.4.7</pagehelper.boot.version>
- <druid.version>1.2.16</druid.version>
- <dynamic-ds.version>3.5.2</dynamic-ds.version>
- <commons.io.version>2.11.0</commons.io.version>
- <velocity.version>2.3</velocity.version>
- <fastjson.version>2.0.34</fastjson.version>
- <jjwt.version>0.9.1</jjwt.version>
- <minio.version>8.2.2</minio.version>
- <poi.version>4.1.2</poi.version>
- <transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
- </properties>
-
- <!-- 依赖声明 -->
- <dependencyManagement>
- <dependencies>
-
- <!-- SpringCloud 微服务 -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
-
- <!-- SpringCloud Alibaba 微服务 -->
- <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>
-
- <!-- SpringBoot 依赖配置 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>${spring-boot.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
-
- <!-- FastDFS 分布式文件系统 -->
- <dependency>
- <groupId>com.github.tobato</groupId>
- <artifactId>fastdfs-client</artifactId>
- <version>${tobato.version}</version>
- </dependency>
-
- <!-- Swagger 依赖配置 -->
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-models</artifactId>
- <version>${swagger.core.version}</version>
- </dependency>
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-annotations</artifactId>
- <version>${swagger.core.version}</version>
- </dependency>
-
- <!-- 验证码 -->
- <dependency>
- <groupId>pro.fessional</groupId>
- <artifactId>kaptcha</artifactId>
- <version>${kaptcha.version}</version>
- </dependency>
-
- <!-- pagehelper 分页插件 -->
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>${pagehelper.boot.version}</version>
- </dependency>
-
- <!-- io常用工具类 -->
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons.io.version}</version>
- </dependency>
-
- <!-- excel工具 -->
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml</artifactId>
- <version>${poi.version}</version>
- </dependency>
-
- <!-- 代码生成使用模板 -->
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-engine-core</artifactId>
- <version>${velocity.version}</version>
- </dependency>
-
- <!-- JSON 解析器和生成器 -->
- <dependency>
- <groupId>com.alibaba.fastjson2</groupId>
- <artifactId>fastjson2</artifactId>
- <version>${fastjson.version}</version>
- </dependency>
-
- <!-- JWT -->
- <dependency>
- <groupId>io.jsonwebtoken</groupId>
- <artifactId>jjwt</artifactId>
- <version>${jjwt.version}</version>
- </dependency>
-
- <!-- 线程传递值 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>transmittable-thread-local</artifactId>
- <version>${transmittable-thread-local.version}</version>
- </dependency>
-
- </dependencies>
- </dependencyManagement>
-
- <modules>
- <module>huangmount-common</module>
- </modules>
- <packaging>pom</packaging>
-
- <dependencies>
- <!-- bootstrap 启动器 -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-bootstrap</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>${spring-boot.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-
- <repositories>
- <repository>
- <id>public</id>
- <name>aliyun nexus</name>
- <url>https://maven.aliyun.com/repository/public</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- </repository>
- </repositories>
-
- <pluginRepositories>
- <pluginRepository>
- <id>public</id>
- <name>aliyun nexus</name>
- <url>https://maven.aliyun.com/repository/public</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
-
- </project>

3.1 继续创建huangmount-modules
3.2 粘贴huangmount-modules, 如下
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>com.huangmount</groupId>
- <artifactId>HuangMount</artifactId>
- <version>3.6.3</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <modules>
- <module>huangmount-modules-system</module>
- </modules>
-
- <artifactId>huangmount-modules</artifactId>
- <packaging>pom</packaging>
-
- <description>
- huangmount-modules业务模块
- </description>
-
- </project>

3.3 创建huangmount-modules-system 模块,该模块为业务系统模块,用于提供接口
3.4 粘贴huangmount-modules-system 模块pom.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://maven.apache.org/POM/4.0.0"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>com.huangmount</groupId>
- <artifactId>huangmount-modules</artifactId>
- <version>3.6.3</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>huangmount-modules-system</artifactId>
-
- <description>
- huangmount-modules-system系统模块
- </description>
-
- <dependencies>
-
- <!-- SpringCloud Alibaba Nacos -->
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
- </dependency>
-
- <!-- SpringCloud Alibaba Nacos Config -->
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
- </dependency>
-
- <!-- SpringCloud Alibaba Sentinel -->
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
- </dependency>
-
- <!-- SpringBoot Actuator -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
-
- <!-- Swagger UI -->
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${swagger.fox.version}</version>
- </dependency>
-
- <!-- Mysql Connector -->
- <dependency>
- <groupId>com.mysql</groupId>
- <artifactId>mysql-connector-j</artifactId>
- </dependency>
-
-
- </dependencies>
-
- <build>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- </project>

3.5 项目结构图如下

启动HuangMountSystemApplication启动类即可成功,如有问题,欢迎留言!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。