実行可能なJARパッケージに加えて、Spring Bootは従来の戦争パッケージもサポートしています。この記事では、Spring Bootを使用して従来の戦争パッケージを構築する方法について説明します。
Spring Bootが戦争パッケージを使用する手順は次のとおりです。
1. pom.xmlでパッケージングタイプを定義します
<パッケージ>戦争</パッケージ>
2。スプリングブートランチャーを追加します(親を介してもできます)
<DependencyManagement> <Dependencies> <Dependency> <! - Spring Boot-> <groupId> org.springframework.boot </groupid> <artifactid> spring-boot-dependencies </artifactid> <バージョン> 1.5.6.release </verseas> <pom/pom </deprat> <sapence> </scope> </scope> </scope> </DependencyManagement>
3. Spring-Boot-Starter-Web依存関係を追加します
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
4.パッケージ化されたプラグインを追加します
<build> <プラグイン><プラグイン> <groupId> org.springframework.boot </groupid> <artifactid> spring-boot-maven-plugin </artifactid> </plugin> </plugins> </build>
5.メインクラスはSpringBootservletinitializerを継承します
/** war Application */@springbootapplicationpublic class warapplicationはspringbootservletinitializer {public static void main(string [] args){springApplication.run(warapplication.class、args); }}6。MVNクリーンパッケージを実行します
$ MVNクリーンパッケージ
7.完成した戦争パッケージをコンテナ(Tomcatなど)にコピーして実行します。
ここで簡単な説明が必要です。
メインアプリケーションは、SpringBootservletInitializerを構成メソッドでオーバーライドし、Spring Bootの構成をカスタマイズできます。
/***アプリケーションを構成します。通常、必要なのは、他の設定には賢明なデフォルトがあるため、ソース *(configクラスなど)を追加することだけです。デフォルトのコマンドライン引数を追加するか、アクティブな *スプリングプロファイルを設定する(たとえば)(たとえば)選択 *します。 * @param Builderアプリケーションコンテキスト用のビルダー * @return the application builder * @see springApplicationBuilder */ Protected SpringApplicationBuilder Configure(SpringApplicationBuilder Builder){return Builder; }インスタンスソースコードをダウンロードします
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。