Browse Source

spring boot 打成 war 包的相关配置

v-1.5.x
yangkai.shen 6 years ago
parent
commit
4a16fcdc54
9 changed files with 163 additions and 3 deletions
  1. +3
    -1
      README.md
  2. +2
    -2
      TODO.md
  3. +1
    -0
      spring-boot-demo-parent/pom.xml
  4. +67
    -0
      spring-boot-demo-war/README.md
  5. +35
    -0
      spring-boot-demo-war/pom.xml
  6. +24
    -0
      spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/ServletInitializer.java
  7. +12
    -0
      spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplication.java
  8. +3
    -0
      spring-boot-demo-war/src/main/resources/application.yml
  9. +16
    -0
      spring-boot-demo-war/src/test/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplicationTests.java

+ 3
- 1
README.md View File

@@ -1,6 +1,6 @@
# Spring Boot Demo

spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过 AOP 记录 web 请求日志)、统一异常处理( json 级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、JPA(ORM 框架)、mybatis(ORM 框架)、redis-cache(缓存)、swagger(API 接口管理测试)、ureport2(中国式报表)模块,后续会集成activemq,email,shiro,websocket,quartz,netty等模块。
spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过 AOP 记录 web 请求日志)、统一异常处理( json 级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、JPA(ORM 框架)、mybatis(ORM 框架)、redis-cache(缓存)、swagger(API 接口管理测试)、ureport2(中国式报表)、打包成 war 文件,后续会集成activemq,email,shiro,websocket,quartz,netty等模块。

依赖的 Spring Boot 版本:

@@ -59,6 +59,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
<module>../spring-boot-demo-cache-redis</module>
<module>../spring-boot-demo-swagger</module>
<module>../spring-boot-demo-ureport2</module>
<module>../spring-boot-demo-war</module>
</modules>

<parent>
@@ -159,6 +160,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
| [spring-boot-demo-cache-redis](./spring-boot-demo-cache-redis) | spring-boot 使用 Redis 做缓存 |
| [spring-boot-demo-swagger](./spring-boot-demo-swagger) | spring-boot 集成 [spring-boot-starter-swagger](https://github.com/SpringForAll/spring-boot-starter-swagger) (由大佬[翟永超](http://blog.didispace.com/)开源)用于统一管理、测试 API 接口 |
| [spring-boot-demo-ureport2](./spring-boot-demo-ureport2) | spring-boot 集成 [ureport2](https://github.com/youseries/ureport) 实现自定义报表(ureport2可以轻松实现复杂的中国式报表,功能十分强大) |
| [spring-boot-demo-war](./spring-boot-demo-war) | spring-boot 打成 war 包的配置 |

# 官方提供的 starter 介绍



+ 2
- 2
TODO.md View File

@@ -1,6 +1,6 @@
# spring-boot-demo 项目

## 模块计划(已完成:14 / 37)
## 模块计划(已完成:15 / 37)

- [x] ~~spring-boot-demo-helloworld(Helloworld 示例)~~
- [x] ~~spring-boot-demo-properties(读取配置文件信息)~~
@@ -38,7 +38,7 @@
- [ ] spring-boot-demo-activiti(集成 Activiti 实现流程控制引擎)
- [ ] spring-boot-demo-async(Spring boot 实现异步调用)
- [ ] spring-boot-demo-dubbo(集成 dubbo)
- [ ] spring-boot-demo-war(打包成war包)
- [x] ~~spring-boot-demo-war(打包成war包)~~

### 备注


+ 1
- 0
spring-boot-demo-parent/pom.xml View File

@@ -26,6 +26,7 @@
<module>../spring-boot-demo-cache-redis</module>
<module>../spring-boot-demo-swagger</module>
<module>../spring-boot-demo-ureport2</module>
<module>../spring-boot-demo-war</module>
</modules>

<parent>


+ 67
- 0
spring-boot-demo-war/README.md View File

@@ -0,0 +1,67 @@
# spring-boot-demo-war

依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-tomcat`

### pom.xml

```xml
<?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>

<artifactId>spring-boot-demo-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 打成 war 包修改的第 ① 处 -->
<packaging>war</packaging>

<name>spring-boot-demo-war</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<dependencies>
<!-- 打成 war 包修改的第 ② 处 -->
<!-- 若需要打成 war 包,则需要将 tomcat 引入,scope 设置为 provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-war</finalName>
</build>

</project>
```

### ServletInitializer.java

```java
/**
* 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer
* <p>打成 war 包修改的第 ③ 处</p>
* @package: com.xkcoding.springbootdemowar
* @description: 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer
* @author: yangkai.shen
* @date: Created in 2017/11/30 下午1:26
* @copyright: Copyright (c) 2017
* @version: 0.0.1
* @modified: yangkai.shen
*/
public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootDemoWarApplication.class);
}

}
```

+ 35
- 0
spring-boot-demo-war/pom.xml View File

@@ -0,0 +1,35 @@
<?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>

<artifactId>spring-boot-demo-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 打成 war 包修改的第 ① 处 -->
<packaging>war</packaging>

<name>spring-boot-demo-war</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<dependencies>
<!-- 打成 war 包修改的第 ② 处 -->
<!-- 若需要打成 war 包,则需要将 tomcat 引入,scope 设置为 provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-war</finalName>
</build>

</project>

+ 24
- 0
spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/ServletInitializer.java View File

@@ -0,0 +1,24 @@
package com.xkcoding.springbootdemowar;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

/**
* 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer
* <p>打成 war 包修改的第 ③ 处</p>
* @package: com.xkcoding.springbootdemowar
* @description: 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer
* @author: yangkai.shen
* @date: Created in 2017/11/30 下午1:26
* @copyright: Copyright (c) 2017
* @version: 0.0.1
* @modified: yangkai.shen
*/
public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootDemoWarApplication.class);
}

}

+ 12
- 0
spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplication.java View File

@@ -0,0 +1,12 @@
package com.xkcoding.springbootdemowar;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootDemoWarApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootDemoWarApplication.class, args);
}
}

+ 3
- 0
spring-boot-demo-war/src/main/resources/application.yml View File

@@ -0,0 +1,3 @@
server:
port: 8080
context-path: /demo

+ 16
- 0
spring-boot-demo-war/src/test/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplicationTests.java View File

@@ -0,0 +1,16 @@
package com.xkcoding.springbootdemowar;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootDemoWarApplicationTests {

@Test
public void contextLoads() {
}

}

Loading…
Cancel
Save