springboot项目打包成war包

springboot项目打包成war包

依赖pom.xml文件

改变打包类型

<packaging>war</packaging>

移除内置tomcat

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>

更改启动类

extends SpringBootServletInitializer一定要加该继承

@SpringBootApplication
@ServletComponentScan(basePackages = "com.example.*")
public class Demo1Application extends SpringBootServletInitializer {

	public static void main(String[] args) {
		SpringApplication.run(Demo1Application.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(Demo1Application.class);
	}

打包

右击项目Debug as/maven build…

springboot项目打包成war包

完成后在该项目本地目录下的target中找到war包
经war包放至tomcat的webapp目录下
启动
完成