この記事では、主にSpringboot+Maven Multi-Moduleプロジェクトの構造、操作、パッケージングを紹介します。それはあなたと共有されます。詳細は次のとおりです。
プロジェクトで使用されるツール:
プロジェクトディレクトリ:
1.アイデアを使用してスプリングブートプロジェクトを作成:ファイル - > new->プロジェクト名はSpringboot -Multiです
2.プロジェクトのSRCディレクトリを削除し、POM.xmlのプロジェクトのパッケージング方法をPOMに変更します。
<GroupId> com.example </groupid> <artifactid> springboot-multi </artifactid> <バージョン> 0.0.1-snapshot </バージョン> <!
3. Springboot-Multiプロジェクトのサブモジュールを作成し、プロジェクトを右クリックし、次のように選択します:new-> Moduleを選択します。
4. 4つのサブモジュールを作成した後、サブモジュールのSRC/Main/JavaおよびSRC/Main/Javaの下のすべてのファイルを削除し(ファイルがスキップされない場合はこれをスキップします)、Webサブモジュールのメインアプリケーションスタートアップクラスのみを保持します。
5。メインプロジェクトpom.xml(<modules>タグがサブモジュールを指定するかどうかに注意)
<modelversion> 4.0.0 </modelversion> <groupid> com.example </groupid> <artifactid> springboot-multi </artifactidi </artifactid> <バージョン> 0.0.1-snapshot </version> <! - POMへの変更 - > <パッケージング> pom </packaging> <name> springimulti </name < <モジュール> web </module> <odule> service </module> <odule> dao> dao </module> <odule> entity </module> </modules> <parent> org.springframework.boot </groupid> <artifactid> spring-boot-starter-parent <リポジトリからのlookup parent-> </parent> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reporting.outputencoding> utf-8 </project.reporting.outputencoding> <Dependency> groupId> org.springframework.boot </groupid> <artifactid> spring-boot-starter-web </artifactid> </dependency> </dependencies> <! - maven-packageを使用する - > <ビルド> <プラグイン><プラグイン> org.maven.plugins> </groupid> <artifactid> maven-compiler-plugin </artifactid> <version> 3.1 </version> <configuration> <source> $ {java.version} </source> <target> $ {java.version} </target> </configuration> </plugin> <plugin.maven.maven.plugins> <Artifactid> maven-surefire-plugin </artifactid> <version> 2.19.1 </version> <configuration> <skiptests> true </skiptests> <! - デフォルトでユニットテストをオフ - > </configuration> </plugin> </plugins> </build> 6。Webサブモジュールpom.xml(サービス、DAO、エンティティサブモジュールに依存)
<modelversion> 4.0.0 </modelversion> <groupid> com.example </groupid> <artifactid> web </artifactid> <version> 0.0.1-snapshot </version> <packaging> jar </packaging> <name> web </name> <説明<artifactid> springboot-multi </artifactid> <バージョン> 0.0.1-snapshot </version> <tarticath> ../ pom.xml </relativepath> </parent> <dependencies> <依存> <groupId> <GroupId> com.example </groupid> <artifactid> dao </artifactid> <version> 0.0.1-snapshot </version> </dependency> <dependency> com.example </groupid> <artifactid>エンティティ</artifactid> <バージョン> 0.0.1-バージョン</バージョン<ユニークなスターター - > <build> <プラグイン><プラグイン> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-maven-plugin </artifactid> <configuration> <! - メインクラスをグローバル一意のエントリとして指定 - > <mainclass> com.ebapplication </dayout> <Executions> <Execution> <Goal> <Gaul>再パッケージ</goal> <! - 生成されたJARパッケージにすべての依存関係をパッケージ化できます - > </goal> </execution> </executions> </plugin> </plugins> </build> </build>
7。サービスサブモジュールpom.xml(DAOおよびエンティティサブモジュールに依存します)
<modelversion> 4.0.0 </modelversion> <groupid> com.example </groupid> <artifactid> service </artifactid> <version> 0.0.1-snapshot </version> <packaging> jar </packaging> <name> service </name> <説明<artifactid> springboot-multi </artifactid> <バージョン> 0.0.1-snapshot </version> <tarticpath> ../ pom.xml </relativepath> </parent> <dependencies> <shentency> <groupid> com.example </groupid> <artifactid> dao < <GroupId> com.example </groupId> <artifactid> entity </artifactid> <version> 0.0.1-snapshot </version> </dependency> </dependency> </dependency>
8。DAOサブモジュールpom.xml(エンティティサブモジュールに依存)
<modelversion> 4.0.0 </modelversion> <groupid> com.example </groupid> <artifactid> dao </artifactid> <バージョン> 0.0.1-snapshot </snapshot> jar </packaging> <name> dao </name> <説明<artifactid> springboot-multi </artifactid> <バージョン> 0.0.1-snapshot </version> <rativepath> ../ pom.xml </relativepath> </parent> <dependencies> <依存関係> <groupid> </依存関係>
9。エンティティサブモジュール
<modelversion> 4.0.0 </modelversion> <groupid> com.example </groupid> <artifactid> entity </artifactid> <version> 0.0.1-snapshot> jar </packaging> <name> entity> entity </name> <説明<artifactid> springboot-multi </artifactid> <バージョン> 0.0.1-snapshot </version> <tarticpath> ../ pom.xml </rerativepath> </parent>
10。pom.xmlファイルで注意を払う必要があるのは次のとおりです。
11。Webサブモジュールのアプリケーションスタートアップクラス:
@RestController @SpringBootApplication public class webApplication {public static void main(string [] args){springApplication.run(webApplication.class、args); } @requestMapping(value = "/test"、method = requestmethod.get)public string test(){return "test success"; }}12。メインメソッドを実行してプロジェクトを開始し、LocalHost:8080/テストにアクセスしてください。次のページは、プロジェクトが正常に構築されていることを示しているように見えます。
13。プロジェクトパッケージコマンド:MVNクリーンパッケージまたは右側のツールバーのグラフィカルインターフェイスを使用して、パッケージを使用します。
14。パッケージングの成功ログ:
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。