springboot打war包
1.<!-- 打包war [1] --><packaging>war</packaging>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--移除SpringBoot内置的toncat 打war包[2]-->
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
3.
<!-- 打包war [3] 添加依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
-
跟springboot的启动类的同级目录下创建WarStarterApplication启动类
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; // 打包war [4] 增加war的启动类 public class WarStarterApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { // 指向Application这个springboot启动类 return builder.sources(Application.class); } }
5.先把clean一下jar包
6.在安装一下install