重要步骤
- springBoot启动类需继承
SpringBootServletInitializer
类并覆盖configure
方法。
@SpringBootApplication
public class SpringBoot08Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//参数为SpringBoot启动类
return builder.sources(SpringBoot08Application.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringBoot08Application.class, args);
}
}
- 在pom.xml中添加
<packaging>war</packging>
- 在pom.xml中配置springBoot打包插件(默认自动添加)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
</plugin>
- 在pom.xml中配置将配置文件编译到类路径
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
- 在pom.xml的build标签下通过finalName指定打包war包的名字
<build>
<finalName>war包的名字</finalName>
</build>