1 将SpringBoot打成war包
(1)添加Tomcat依赖,去除Tomcat
<!-- 设置tomcat在打包时去除--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
(2)将jar包修改为war包
<packaging>war</packaging>
(3)添加Servelt依赖
这一步我并没有使用,也可以
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
(4)修改启动类
@SpringBootApplication public class DemoApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(DemoApplication.class); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
(5)修改打包名称
<build> <finalName>lock</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
用finalName定义最后输出的war包的名称。
0