SpringBoot部署War包启动
前言
为兼容老项目需要采用War包方式启动,但现有系统又已使用SpringBoot技术。
一、Maven配置
1、设置打包方式
<packaging>war</packaging>
2、 SpringBoot移除Tomcat依赖
<!-- Web 相关 --><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
3、新增外置Tomcat依赖
<!-- 新增外置tomcat依赖 --><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${springboot.version}</version>
<scope>provided</scope>
</dependency>
4、Build配置war包插件
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
二、配置War包启动入口
/** * 兼容War包启动
*
* @author wsh
* @version 1.0
* @date 2020/4/16
* @since JDK1.8
*/
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//此处的Application.class为带有@SpringBootApplication注解的启动类
return builder.sources(Application.class);
}
}
以上是 SpringBoot部署War包启动 的全部内容, 来源链接: utcz.com/z/515728.html