From 785b04c15668fa49843382ecd0980ae48e43cb9c Mon Sep 17 00:00:00 2001
From: "Yangkai.Shen" <237497819@qq.com>
Date: Wed, 31 Oct 2018 22:18:07 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20spring-boot-demo-war=20=E5=AE=8C?=
=?UTF-8?q?=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
spring-boot-demo-war/README.md | 102 ++++++++++++++++++
spring-boot-demo-war/pom.xml | 94 ++++++++--------
.../war/SpringBootDemoWarApplication.java | 12 ++-
.../src/main/resources/application.yml | 4 +
4 files changed, 168 insertions(+), 44 deletions(-)
create mode 100644 spring-boot-demo-war/README.md
diff --git a/spring-boot-demo-war/README.md b/spring-boot-demo-war/README.md
new file mode 100644
index 0000000..8976045
--- /dev/null
+++ b/spring-boot-demo-war/README.md
@@ -0,0 +1,102 @@
+# spring-boot-demo-war
+
+> 本 demo 主要演示了如何将 Spring Boot 项目打包成传统的 war 包程序。
+
+## pom.xml
+
+```xml
+
+
+ * 启动器 + *
+ * + * @package: com.xkcoding.war + * @description: 启动器 + * @author: shenyangkai + * @date: Created in 2018/10/30 19:37 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: shenyangkai + */ +@SpringBootApplication +public class SpringBootDemoWarApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoWarApplication.class, args); + } + + /** + * 若需要打成 war 包,则需要写一个类继承 {@link SpringBootServletInitializer} 并重写 {@link SpringBootServletInitializer#configure(SpringApplicationBuilder)} + */ + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringBootDemoWarApplication.class); + } +} +``` + +## 参考 + +https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#howto-create-a-deployable-war-file + diff --git a/spring-boot-demo-war/pom.xml b/spring-boot-demo-war/pom.xml index 6d8f250..38fc08a 100644 --- a/spring-boot-demo-war/pom.xml +++ b/spring-boot-demo-war/pom.xml @@ -1,48 +1,56 @@@@ -17,9 +19,17 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * @modified: shenyangkai */ @SpringBootApplication -public class SpringBootDemoWarApplication { +public class SpringBootDemoWarApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootDemoWarApplication.class, args); } + + /** + * 若需要打成 war 包,则需要写一个类继承 {@link SpringBootServletInitializer} 并重写 {@link SpringBootServletInitializer#configure(SpringApplicationBuilder)} + */ + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringBootDemoWarApplication.class); + } } diff --git a/spring-boot-demo-war/src/main/resources/application.yml b/spring-boot-demo-war/src/main/resources/application.yml index e69de29..a02fbde 100644 --- a/spring-boot-demo-war/src/main/resources/application.yml +++ b/spring-boot-demo-war/src/main/resources/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 + servlet: + context-path: /demo \ No newline at end of file