Spring boot 打 war 包

第一步

在启动类的同级目录下新建一个 ServletInitializer.java

1
2
3
4
5
6
7
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// DemoApplication.class 是启动类
return application.sources(DemoApplication.class);
}
}

第二步

修改 maven 的打包方式为 war

1
<packaging>war</packaging>

小节

看网上很多教程要加入

1
2
3
4
5
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

但我测试的时候不加入也能打包, 用 tomcat 也能运行和访问,所以教程里就没写这个了

作者

坑 飞

发布于

2019-06-28

更新于

2021-09-06

许可协议

评论