- 先得有一个 SpringBoot 项目
1.1 具体创建方法见 - 修改 pom.xml
建完 SpringBoot 后一就增加一个war,其它没改
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>templates</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 修改 packaging 为 war -->
<packaging>war</packaging>
<name>templates</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- 修改启动类﹡Application,继承 SpringBootServletInitializer 类
如下:
@SpringBootApplication
public class TemplatesApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TemplatesApplication.class, args);
}
}
- 如果用 tomcat 启动项目
按 https://blog.youkuaiyun.com/qq_23878541/article/details/90147223 的 步骤5 即可 - 如果想要打 war 包
按 https://blog.youkuaiyun.com/qq_23878541/article/details/90158167 的 所有步骤 即可