小さなチャット: 今回は Xiaobai が SpringCloud プロジェクトをビルドするための詳細な手順を提供します. 実際, 新しいプロジェクトを作成することは難しくありません. 初心者にとって混乱するのは pom.xml の依存関係のインポートと選択についてです.依存バージョンの。したがって、次に Xiaobaihui は、最新の公式 SpringCloudAlibaba プロジェクトの依存関係の選択をもたらします.もちろん、Xiaobaihui は、最終的な構成結果について話すだけでなく、プロジェクトのバージョンを選択する方法を思い出させます.つまり、次のことができます.いつでも参照して、将来的に最新かつ最適な依存関係バージョンの組み合わせを選択できるようにしてください。したがって、SpringCloud マイクロサービスのみが必要な場合は、それが可能です。Xiaobai は SpringCloudAlibaba マイクロサービス プロジェクトを開発してデプロイしたので、問題はありません。
注: Xiaobai がここで強調しているのは、主に SpringCloudAlibaba シリーズ、SpringCloud および SpringBoot のバージョンの組み合わせを含む、最新かつ最も一致する依存バージョンの組み合わせです。あるテクノロジーの最新バージョンが他のテクノロジーの最新バージョンと必ずしも一致するとは限らないため、これが「最適な」組み合わせの推奨事項です。公式サイトに基づいて推奨されているので、心配する必要はありません。実際には非常に簡単です。公式サイトのバージョンを見てください。以下に、対応するサイトと公式サイトが推奨するコンテンツを掲載します。
- 1. 各技術に関連するウェブサイト
- 2. SpringCloud マイクロサービス プロジェクトの適応バージョンの推奨
- 3.Spring Cloud Alibaba 製品バージョンの推奨
- 4. 例: 最新の SpringCloudAlibaba マイクロサービス プロジェクトを作成する
- エッセイ
1. 各技術に関連するウェブサイト
1) SpringBoot関連
SpringBoot github バージョンのアドレス: https://github.com/spring-projects/spring-boot/releases
SpringBoot 公式サイトアドレス: https://spring.io/projects/spring-boot/
2) 春雲関連
SpringCloud 公式ウェブサイト アドレス: https://spring.io/projects/spring-cloud
3) Spring Cloud アリババ関連
SpringCloudAlibaba github バージョン アドレス: https://github.com/alibaba/spring-cloud-alibaba/releases
SpringCloud 公式サイトアドレス: https://spring.io/projects/spring-cloud-alibaba/
2. SpringCloud マイクロサービス プロジェクトの適応バージョンの推奨
これは主に Springboot での適応です。Springboot が技術的な依存関係の多くのバージョンを自動的に管理および統合する「本番」Spring プロジェクトであることは誰もが知っているため、ここでは SpringCloud と SpringBoot を一致させるだけで済みます。
公式サイト推奨URL: https: //spring.io/projects/spring-cloud#overview
2.1. より詳細版に対応した閲覧方法
https://start.spring.io/actuator/info
これは Json 文字列ページです。オンラインの Json フォーマット ツールを使用して表示してください: http://www.jsons.cn/jsoncheck/
{
"git": {
"branch": "d8ae4573f747cfd71693fb5a41916681b1126aa7",
"commit": {
"id": "d8ae457",
"time": "2022-11-12T16:35:20Z"
}
},
"build": {
"version": "0.0.1-SNAPSHOT",
"artifact": "start-site",
"versions": {
"spring-boot": "2.7.5",
"initializr": "0.20.0-SNAPSHOT"
},
"name": "start.spring.io website",
"time": "2022-11-12T16:38:14.902Z",
"group": "io.spring.start"
},
"bom-ranges": {
"codecentric-spring-boot-admin": {
"2.4.3": "Spring Boot >=2.3.0.M1 and <2.5.0-M1",
"2.5.6": "Spring Boot >=2.5.0.M1 and <2.6.0-M1",
"2.6.8": "Spring Boot >=2.6.0.M1 and <2.7.0-M1",
"2.7.4": "Spring Boot >=2.7.0.M1 and <3.0.0-M1",
"3.0.0-M4": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
},
"solace-spring-boot": {
"1.1.0": "Spring Boot >=2.3.0.M1 and <2.6.0-M1",
"1.2.2": "Spring Boot >=2.6.0.M1 and <3.0.0-M1"
},
"solace-spring-cloud": {
"1.1.1": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"2.1.0": "Spring Boot >=2.4.0.M1 and <2.6.0-M1",
"2.3.2": "Spring Boot >=2.6.0.M1 and <3.0.0-M1"
},
"spring-cloud": {
"Hoxton.SR12": "Spring Boot >=2.2.0.RELEASE and <2.4.0.M1",
"2020.0.6": "Spring Boot >=2.4.0.M1 and <2.6.0-M1",
"2021.0.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-M3",
"2021.0.0-M3": "Spring Boot >=2.6.0-M3 and <2.6.0-RC1",
"2021.0.0-RC1": "Spring Boot >=2.6.0-RC1 and <2.6.1",
"2021.0.5": "Spring Boot >=2.6.1 and <3.0.0-M1",
"2022.0.0-M1": "Spring Boot >=3.0.0-M1 and <3.0.0-M2",
"2022.0.0-M2": "Spring Boot >=3.0.0-M2 and <3.0.0-M3",
"2022.0.0-M3": "Spring Boot >=3.0.0-M3 and <3.0.0-M4",
"2022.0.0-M4": "Spring Boot >=3.0.0-M4 and <3.0.0-M5",
"2022.0.0-M5": "Spring Boot >=3.0.0-M5 and <3.0.0-RC1",
"2022.0.0-RC1": "Spring Boot >=3.0.0-RC1 and <3.1.0-M1"
},
"spring-cloud-azure": {
"4.3.0": "Spring Boot >=2.5.0.M1 and <2.7.0-M1",
"4.4.1": "Spring Boot >=2.7.0-M1 and <3.0.0-M1",
"6.0.0-beta.3": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
},
"spring-cloud-gcp": {
"2.0.11": "Spring Boot >=2.4.0-M1 and <2.6.0-M1",
"3.4.0": "Spring Boot >=2.6.0-M1 and <3.0.0-M1"
},
"spring-cloud-services": {
"2.3.0.RELEASE": "Spring Boot >=2.3.0.RELEASE and <2.4.0-M1",
"2.4.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"3.3.0": "Spring Boot >=2.5.0-M1 and <2.6.0-M1",
"3.4.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1",
"3.5.0": "Spring Boot >=2.7.0-M1 and <3.0.0-M1"
},
"spring-shell": {
"2.1.3": "Spring Boot >=2.7.0 and <3.0.0-M1",
"3.0.0-M2": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
},
"vaadin": {
"14.9.1": "Spring Boot >=2.1.0.RELEASE and <2.6.0-M1",
"23.2.7": "Spring Boot >=2.6.0-M1 and <2.8.0-M1"
},
"wavefront": {
"2.0.2": "Spring Boot >=2.1.0.RELEASE and <2.4.0-M1",
"2.1.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"2.2.2": "Spring Boot >=2.5.0-M1 and <2.7.0-M1",
"2.3.0": "Spring Boot >=2.7.0-M1 and <3.0.0-M1"
}
},
"dependency-ranges": {
"native": {
"0.9.0": "Spring Boot >=2.4.3 and <2.4.4",
"0.9.1": "Spring Boot >=2.4.4 and <2.4.5",
"0.9.2": "Spring Boot >=2.4.5 and <2.5.0-M1",
"0.10.0": "Spring Boot >=2.5.0-M1 and <2.5.2",
"0.10.1": "Spring Boot >=2.5.2 and <2.5.3",
"0.10.2": "Spring Boot >=2.5.3 and <2.5.4",
"0.10.3": "Spring Boot >=2.5.4 and <2.5.5",
"0.10.4": "Spring Boot >=2.5.5 and <2.5.6",
"0.10.5": "Spring Boot >=2.5.6 and <2.5.9",
"0.10.6": "Spring Boot >=2.5.9 and <2.6.0-M1",
"0.11.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-RC1",
"0.11.0-M2": "Spring Boot >=2.6.0-RC1 and <2.6.0",
"0.11.0-RC1": "Spring Boot >=2.6.0 and <2.6.1",
"0.11.0": "Spring Boot >=2.6.1 and <2.6.2",
"0.11.1": "Spring Boot >=2.6.2 and <2.6.3",
"0.11.2": "Spring Boot >=2.6.3 and <2.6.4",
"0.11.3": "Spring Boot >=2.6.4 and <2.6.6",
"0.11.5": "Spring Boot >=2.6.6 and <2.7.0-M1",
"0.12.0": "Spring Boot >=2.7.0-M1 and <2.7.1",
"0.12.1": "Spring Boot >=2.7.1 and <3.0.0-M1"
},
"okta": {
"1.4.0": "Spring Boot >=2.2.0.RELEASE and <2.4.0-M1",
"1.5.1": "Spring Boot >=2.4.0-M1 and <2.4.1",
"2.0.1": "Spring Boot >=2.4.1 and <2.5.0-M1",
"2.1.6": "Spring Boot >=2.5.0-M1 and <3.0.0-M1"
},
"mybatis": {
"2.1.4": "Spring Boot >=2.1.0.RELEASE and <2.5.0-M1",
"2.2.2": "Spring Boot >=2.5.0-M1"
},
"camel": {
"3.5.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"3.10.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1",
"3.13.0": "Spring Boot >=2.5.0.M1 and <2.6.0-M1",
"3.17.0": "Spring Boot >=2.6.0.M1 and <2.7.0-M1",
"3.19.0": "Spring Boot >=2.7.0.M1 and <3.0.0-M1"
},
"picocli": {
"4.6.3": "Spring Boot >=2.4.0.RELEASE and <3.0.0-M1"
},
"open-service-broker": {
"3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"3.3.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"3.4.1": "Spring Boot >=2.5.0-M1 and <2.6.0-M1",
"3.5.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1"
}
}
}
2.2. 推奨される使用法
SpringBoot のみを使用する場合は、最新のものを使用してください。
SpringCloud マイクロサービス プロジェクトを使用する場合、SpringCloud は最新バージョンを使用し、SpringBoot は最適なバージョンを見つけます。
3.Spring Cloud Alibaba 製品バージョンの推奨
Spring Cloud Alibaba の依存バージョンには、nacos、seata、sentinel、rocketmq など、Spring Cloud 開発フレームワークに関連する Alibaba 独自のバージョン コレクションが統合されています。これらの製品を使用する場合は、Spring Cloud のバージョンに対応している必要があります。最新の SpringCloudAlibaba 製品を使用するには、まず SpringCloudAlibaba が依存する最新バージョンを選択してから、SpringCloud と SpringBoot のバージョンを選択する必要があります。(SpringCloudAlibaba は更新されるほど高速ではないため)
正式版説明URL:
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
以下は公式テキストです、直接取りました〜
3.1. 卒業バージョンの依存関係 (推奨)
Spring Boot 2.4+ と以降のバージョン間の大幅な変更により、企業顧客の古いプロジェクトに関連する現在の Spring Boot バージョンはまだ Spring Boot 2.4 未満です. 既存のユーザーと新しいユーザーのさまざまなニーズを満たすために、同時に、コミュニティは Spring Boot 2.4 Boundary に分割され、2.2.x と 2021.x の 2 つのブランチ イテレーションが維持されます。
1) 2021.x ブランチ
Spring Boot 2.4、Spring Cloud 2021.x 以降に適応した Spring Cloud Alibaba のバージョンは、次の表に新しいものから古いものへと並べられています (最新バージョンは * でマークされています): (このブランチ Spring Cloud の命名方法に注意してください。アリババのバージョンが調整されました. 将来的にはSpring Cloudバージョンに対応する予定です. 最初の3桁がSpring Cloudバージョンで、最後の桁が拡張バージョンです. たとえば、最初に対応するSpring Cloud Alibabaのバージョンは、 Spring Cloud 2021.0.1 バージョンは 2021.0.1.0、2 番目のバージョンは 2021.0.1.1 など)
春の雲 アリババ版 | 春の雲バージョン | スプリング ブート バージョン |
---|---|---|
2021.0.4.0* | 春の雲 2021.0.4 | 2.6.11 |
2021.0.1.0 | 春の雲 2021.0.1 | 2.6.3 |
2021.1 | 春の雲 2020.0.1 | 2.4.2 |
2) 2.2.x ブランチ
Spring Boot 2.4 に対応した Spring Cloud Hoxton のバージョンと、次の Spring Cloud Alibaba のバージョンを、新しいものから順に次の表に示します (最新バージョンは * でマークされています)。
春の雲 アリババ版 | 春の雲バージョン | スプリング ブート バージョン |
---|---|---|
2.2.9.リリース* | スプリング クラウド ホクストン.SR12 | 2.3.12.リリース |
2.2.8.リリース | スプリング クラウド ホクストン.SR12 | 2.3.12.リリース |
2.2.7.リリース | スプリング クラウド ホクストン.SR12 | 2.3.12.リリース |
2.2.6.リリース | スプリング クラウド ホクストン.SR9 | 2.3.2.リリース |
2.2.1.リリース | スプリング クラウド ホクストン.SR3 | 2.2.5.リリース |
2.2.0.リリース | 春の雲 Hoxton.RELEASE | 2.2.X.リリース |
2.1.4.リリース | スプリング クラウド グリニッジ.SR6 | 2.1.13.リリース |
2.1.2.リリース | 春の雲 グリニッジ | 2.1.X.リリース |
2.0.4.RELEASE (メンテナンスを停止、アップグレードを推奨) | スプリング クラウド フィンチリー | 2.0.X.リリース |
1.5.1.RELEASE (メンテナンスを停止、アップグレードを推奨) | Spring クラウド エッジウェア | 1.5.X.リリース |
3.2. コンポーネントのバージョン関係
Spring Cloud Alibaba の各バージョンと、それが適応する各コンポーネントの対応するバージョンを次の表に示します (Spring Cloud Dubbo は 2021.0.1.0 以降、トランクから削除されており、トランクと共に進化しないことに注意してください)。
春の雲 アリババ版 | 千値練バージョン | ナコスバージョン | RocketMQ バージョン | ダボバージョン | シータ版 |
---|---|---|---|---|---|
2.2.9.リリース | 1.8.5 | 2.1.0 | 4.9.4 | 〜 | 1.5.2 |
2021.0.4.0 | 1.8.5 | 2.0.4 | 4.9.4 | 〜 | 1.5.2 |
2.2.8.リリース | 1.8.4 | 2.1.0 | 4.9.3 | 〜 | 1.5.1 |
2021.0.1.0 | 1.8.3 | 1.4.2 | 4.9.2 | 〜 | 1.4.2 |
2.2.7.リリース | 1.8.1 | 2.0.3 | 4.6.1 | 2.7.13 | 1.3.0 |
2.2.6.リリース | 1.8.1 | 1.4.2 | 4.4.0 | 2.7.8 | 1.3.0 |
2021.1 または 2.2.5.RELEASE または 2.1.4.RELEASE または 2.0.4.RELEASE | 1.8.0 | 1.4.1 | 4.4.0 | 2.7.8 | 1.3.0 |
2.2.3.RELEASE または 2.1.3.RELEASE または 2.0.3.RELEASE | 1.8.0 | 1.3.3 | 4.4.0 | 2.7.8 | 1.3.0 |
2.2.1.RELEASE または 2.1.2.RELEASE または 2.0.2.RELEASE | 1.7.1 | 1.2.1 | 4.4.0 | 2.7.6 | 1.2.0 |
2.2.0.リリース | 1.7.1 | 1.1.4 | 4.4.0 | 2.7.4.1 | 1.0.0 |
2.1.1.RELEASE または 2.0.1.RELEASE または 1.5.1.RELEASE | 1.7.0 | 1.1.4 | 4.4.0 | 2.7.3 | 0.9.0 |
2.1.0.RELEASE または 2.0.0.RELEASE または 1.5.0.RELEASE | 1.6.3 | 1.1.1 | 4.4.0 | 2.7.3 | 0.7.1 |
4. 例: 最新の SpringCloudAlibaba マイクロサービス プロジェクトを作成する
わあ、ついにここに来ました... Here we take the latest and most appropriate version of SpringCloud microservices with SpringCloudAlibaba products as an example. SpringCloud マイクロサービス プロジェクトだけが必要な場合は、上記の公式の推奨に従って次の例を参照できます。 . 構成してビルドします。
4.1. 最も単純な Maven プロジェクトを使用して、新しい親プロジェクト プロジェクトを作成します。
1) Maven プロジェクトの初期フレームワーク、jdk バージョンを選択し、名前を付け、場所を指定します。
初期フレームワーク: org.apache.maven.archetypes:maven-archetype-site
jdk バージョン: jkd1.8
名前:SpringCloud2022
2) ファイルを開く ——> 設定、Maven を検索し、Maven を自分でインストールするパスを指定して、pom 座標ファイルのインポートを容易にします。
3) 準備した親プロジェクトの pom.xml ファイルを使用して、準備した SpringCloud バージョンのメイン環境を指定します. 準備した pom.xml ファイルの内容は次のとおりです.
<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.byy.springbloud</groupId>
<artifactId>SpringCloud2022</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>user-service</module>
</modules>
<!-- 修改打包方式 -->
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- 2022.11.16 SpringCloudAlibaba2021.x 最新适配版3SpringXXX搭配 -->
<spring-boot.version>2.6.11</spring-boot.version>
<spring-cloud.version>2021.0.4</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.4.0</spring-cloud-alibaba.version>
<!-- mybatis-plus 选择版本适配spring-boot -->
<mybatis-plus.version>3.5.1</mybatis-plus.version>
<!-- 2022.11.16 SpringCloudAlibaba2.2.x 最新适配版3SpringXXX搭配 -->
<!-- <spring-boot.version>2.3.12.RELEASE</spring-boot.version>-->
<!-- <spring-cloud.version>Hoxton.SR12</spring-cloud.version>-->
<!-- <spring-cloud-alibaba.version>2.2.9.RELEASE</spring-cloud-alibaba.version>-->
<!-- <mybatis-plus.version>3.4.2</mybatis-plus.version>-->
<mysql.version>8.0.22</mysql.version>
<fastjson.version>2.0.18</fastjson.version>
<junit.version>4.13.2</junit.version>
<lombok.version>1.18.24</lombok.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<!-- 因为是总项目 所以用dependencyManagement来管理;其他的子项目就不会来管理版本了了 可以直接引用 -->
<dependencyManagement>
<dependencies>
<!-- springBoot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<!-- type和scope标签:让子model可以多继承父model -->
<!-- <type></type> 里的值默认值是jar表示引入的是jar包,这里使用的是pom表示导入的是父模块; -->
<!-- <scope></scope>中的值import代表把父模块中的jar包导入进来,不过需要注意的是<scope>import</scope>, -->
<!-- 这种方式只能用在<dependencyManagement></dependencyManagement>中。 -->
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- springCloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- springCloudAlibaba -->
<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>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- Java对象和JSON相互转换 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- JavaBean 注解构建 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</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>
4.2. 新しいサブプロジェクトを作成する
1) 新しいサブモジュール Maven プロジェクトを選択します
あ、念のため親プロジェクトの src ディレクトリはダメで削除、目障りです、.idea ディレクトリは隠してあるので大丈夫です。非表示にする方法 [設定] --> [エディター] --> [ファイルの種類] に移動し、[無視されたファイルとフォルダー] 列をクリックします。他の非表示のファイル形式があります。*.idea を追加するなど、それに続きます。
2) Maven サブプロジェクトの設定を構成する
ここでは、Spring Initializer の代わりに Maven プロジェクトを選択することをお勧めします. これは確かに、新しい SpringBoot/SpringCloud プロジェクトを作成するために使用されますが、デフォルトではサブモジュールにはなりません. つまり、独立したプロジェクトになります. ただし、先ほど作成した親プロジェクトのディレクトリにあるだけなのですが、親プロジェクトのpom座標を継承するように自動的に設定されるわけではなく、サブモジュールの<modules>
ラベルを デフォルトでサブモジュールとして設定される Maven プロジェクトを選択するのが最善であり、pom.xml には依存座標がなく、いつでも必要なものを追加できます。
ここでは、フレームワークとして org.apache.maven.archetypes:maven-archetype-webapp を選択しました. これは Web フレームワークです. 私はそれが好きで、Web プロジェクトのディレクトリ構造を構築するのに役立ちます. Web 関数モジュールではありません。そうであれば、別のフレームワークを選択してください。要するに、最終的には自分で変更できます。あまり絡まないでください。
3) サブモジュール user-service の pom.xml 構成を変更します。
まあ、自分のサブプロジェクトの要件に応じて依存関係をインポートする必要があります. 以下に詳しく書きますが、それほど多くは使用しないかもしれません. 参照として使用できます.
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>SpringCloud2022</artifactId>
<groupId>com.byy.springbloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<!-- 模块名称 -->
<artifactId>user-service</artifactId>
<!-- 注意,子项目模块就是 dependencies 了,是真正需要导入包的,版本则不需要指定 -->
<dependencies>
<!-- Web开发 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringBoot应用的监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- SpringBoot测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- springboot统一封装的消息中间件框架 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--引入es的RestHighLevelClient依赖-->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
<!-- nacos客户端依赖包 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--nacos的配置管理依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 配置sentinel规则持久化,引入sentinel监听nacos的依赖 -->
<!-- 为了减少开发的复杂程度,Sentinel 对大部分的主流框架做了适配, -->
<!-- 例如 SpringMVC、WebFlux、Dubbo、Spring Cloud、RocketMQ 等等。 -->
<!-- 我们只需要引入对应的 sentinel-apache-xxx-adapter 依赖,即可方便地整合 Sentinel。 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- sentinel微服务保护 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 配置spring-webmvc集成sentinel,做web监控 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-webmvc-adapter</artifactId>
</dependency>
<!-- gateway网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- seata全局事务控制 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<!-- openfeign RPC远程调用 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- kafka 消息中间件 -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- springboot热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Java对象和JSON相互转换 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!-- JavaBean 注解构建 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- 日志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
</dependencies>
<!-- 每个子项目可单独打包然后分发到各自服务器部署 -->
<build>
<!-- 文件项目打包名字,不设置默认是artifactId与version拼接的结果 -->
<finalName>user-service</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 热部署配置需添加以下configuration,不加该配置可能不会生效。不需要热部署可以去掉 -->
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
さて、マイクロサービス プロジェクトの基本的な構成は完了しました。サブプロジェクトをさらに追加しても問題ありません。